Adopt planes to Part size

This commit is contained in:
Stefan Tröger 2015-05-04 22:31:38 +02:00
parent ae3916229d
commit 8134cf3cf4
6 changed files with 130 additions and 42 deletions

View File

@ -54,10 +54,14 @@ PROPERTY_SOURCE(Gui::ViewProviderGeoFeatureGroup, Gui::ViewProviderGeometryObjec
ViewProviderGeoFeatureGroup::ViewProviderGeoFeatureGroup()
{
pcGroupChildren = new SoGroup();
pcGroupChildren->ref();
}
ViewProviderGeoFeatureGroup::~ViewProviderGeoFeatureGroup()
{
pcGroupChildren->unref();
pcGroupChildren = 0;
}
@ -95,6 +99,30 @@ QIcon ViewProviderGeoFeatureGroup::getIcon() const
return groupIcon;
}
void ViewProviderGeoFeatureGroup::attach(App::DocumentObject* pcObject)
{
addDisplayMaskMode(pcGroupChildren, "Part");
Gui::ViewProviderGeometryObject::attach(pcObject);
}
void ViewProviderGeoFeatureGroup::setDisplayMode(const char* ModeName)
{
if ( strcmp("Part",ModeName)==0 )
setDisplayMaskMode("Part");
ViewProviderGeometryObject::setDisplayMode( ModeName );
}
std::vector<std::string> ViewProviderGeoFeatureGroup::getDisplayModes(void) const
{
// get the modes of the father
std::vector<std::string> StrList = ViewProviderGeometryObject::getDisplayModes();
// add your own modes
StrList.push_back("Part");
return StrList;
}
// Python feature -----------------------------------------------------------------------

View File

@ -43,8 +43,12 @@ public:
virtual std::vector<App::DocumentObject*> claimChildren(void)const;
virtual std::vector<App::DocumentObject*> claimChildren3D(void)const;
virtual SoGroup* getChildRoot(void) const {return pcGroupChildren;};
QIcon getIcon(void) const;
virtual void attach(App::DocumentObject* pcObject);
virtual void setDisplayMode(const char* ModeName);
virtual std::vector<std::string> getDisplayModes(void) const;
virtual bool onDelete(const std::vector<std::string> &);
@ -52,8 +56,9 @@ public:
//virtual bool allowDrop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos);
/// get called if the user drops some objects
//virtual void drop(const std::vector<const App::DocumentObject*> &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos);
protected:
SoGroup *pcGroupChildren;
};
typedef ViewProviderPythonFeatureT<ViewProviderGeoFeatureGroup> ViewProviderGeoFeatureGroupPython;

View File

@ -34,6 +34,7 @@
/// Here the FreeCAD includes sorted by Base,App,Gui......
#include "ViewProviderPart.h"
#include "ViewProviderPlane.h"
#include "Application.h"
#include "Command.h"
#include "BitmapFactory.h"
@ -42,6 +43,10 @@
#include "View3DInventor.h"
#include "View3DInventorViewer.h"
#include "Base/Console.h"
#include <boost/bind.hpp>
#include <Inventor/actions/SoGetBoundingBoxAction.h>
#include <Inventor/nodes/SoSeparator.h>
using namespace Gui;
@ -67,17 +72,73 @@ ViewProviderPart::~ViewProviderPart()
*/
void ViewProviderPart::onChanged(const App::Property* prop)
{
ViewProviderDocumentObject::onChanged(prop);
ViewProviderGeoFeatureGroup::onChanged(prop);
}
void ViewProviderPart::attach(App::DocumentObject *pcObj)
{
ViewProviderDocumentObject::attach(pcObj);
pcObj->getDocument()->signalChangedObject.connect(boost::bind(&ViewProviderPart::onObjectChanged, this, _1, _2));
ViewProviderGeoFeatureGroup::attach(pcObj);
}
void ViewProviderPart::updateData(const App::Property* prop)
{
ViewProviderGeoFeatureGroup::updateData(prop);
}
void ViewProviderPart::onObjectChanged(const App::DocumentObject& obj, const App::Property&)
{
App::Part* part = static_cast<App::Part*>(pcObject);
if(static_cast<App::Part*>(pcObject)->hasObject(&obj) && obj.getTypeId() != App::Plane::getClassTypeId()) {
View3DInventorViewer* viewer = static_cast<View3DInventor*>(this->getActiveView())->getViewer();
SoGetBoundingBoxAction bboxAction(viewer->getSoRenderManager()->getViewportRegion());
//calculate for everything but planes
SbBox3f bbox(0.0001f,0.0001f,0.0001f,0.0001f,0.0001f,0.0001f);
for(App::DocumentObject* obj : part->getObjects()) {
if(obj->getTypeId() != App::Plane::getClassTypeId()) {
bboxAction.apply(Gui::Application::Instance->getViewProvider(obj)->getRoot());
bbox.extendBy(bboxAction.getBoundingBox());
}
};
//get the bounding box values
SbVec3f size = bbox.getSize()*1.3;
SbVec3f max = bbox.getMax()*1.3;
SbVec3f min = bbox.getMin()*1.3;
//get the planes and set their values
std::vector<App::DocumentObject*> planes = part->getObjectsOfType(App::Plane::getClassTypeId());
for (std::vector<App::DocumentObject*>::const_iterator p = planes.begin(); p != planes.end(); p++) {
Gui::ViewProviderPlane* vp = dynamic_cast<Gui::ViewProviderPlane*>(Gui::Application::Instance->getViewProvider(*p));
if (strcmp(App::Part::BaseplaneTypes[0], dynamic_cast<App::Plane*>(*p)->getNameInDocument()) == 0) {
Base::Placement cpl = dynamic_cast<App::Plane*>(*p)->Placement.getValue();
cpl = Base::Placement(-cpl.getPosition() + Base::Vector3d((max[0]+min[0])/2., (max[1]+min[1])/2., 0), Base::Rotation());
//dynamic_cast<App::Plane*>(*p)->Placement.setValue(cpl);
if(vp)
vp->Size.setValue(std::max(std::abs(std::min(min[0], min[1])),std::max(max[0], max[1])));
}
if (strcmp(App::Part::BaseplaneTypes[1], dynamic_cast<App::Plane*>(*p)->getNameInDocument()) == 0) {
Base::Placement cpl = dynamic_cast<App::Plane*>(*p)->Placement.getValue();
cpl = Base::Placement(-cpl.getPosition() + Base::Vector3d((max[0]+min[0])/2., 0, (max[2]+min[2])/2.), Base::Rotation());
//dynamic_cast<App::Plane*>(*p)->Placement.setValue(cpl);
if(vp)
vp->Size.setValue(std::max(std::abs(std::min(min[0], min[2])),std::max(max[0], max[2])));
}
if (strcmp(App::Part::BaseplaneTypes[2], dynamic_cast<App::Plane*>(*p)->getNameInDocument()) == 0) {
Base::Placement cpl = dynamic_cast<App::Plane*>(*p)->Placement.getValue();
cpl = Base::Placement(-cpl.getPosition() + Base::Vector3d(0, (max[1]+min[1])/2., (max[2]+min[2])/2.), Base::Rotation());
//dynamic_cast<App::Plane*>(*p)->Placement.setValue(cpl);
if(vp)
vp->Size.setValue(std::max(std::abs(std::min(min[1], min[2])),std::max(max[1], max[2])));
}
}
}
}
@ -91,12 +152,6 @@ bool ViewProviderPart::doubleClicked(void)
}
std::vector<std::string> ViewProviderPart::getDisplayModes(void) const
{
// empty
return std::vector<std::string>();
}
bool ViewProviderPart::onDelete(const std::vector<std::string> &)
{
//Gui::Command::doCommand(Gui::Command::Doc,"App.getDocument(\"%s\").getObject(\"%s\").removeObjectsFromDocument()"
@ -104,22 +159,6 @@ bool ViewProviderPart::onDelete(const std::vector<std::string> &)
return true;
}
void ViewProviderPart::hide(void)
{
}
void ViewProviderPart::show(void)
{
}
bool ViewProviderPart::isShow(void) const
{
return Visibility.getValue();
}
void ViewProviderPart::Restore(Base::XMLReader &reader)
{
Visibility.StatusBits.set(9); // tmp. set
@ -168,19 +207,19 @@ void ViewProviderPart::setUpPart(const App::Part *part)
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", part->getNameInDocument());
//Gui::Command::doCommand(Gui::Command::Doc,"OGroup.addObject(App.activeDocument().ActiveObject)");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')", App::Part::BaseplaneTypes[1]);
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(1,0,0),-90))");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')", App::Part::BaseplaneTypes[1]);
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(1,0,0),90))");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("XZ-Plane").toStdString().c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", part->getNameInDocument());
//Gui::Command::doCommand(Gui::Command::Doc,"OGroup.addObject(App.activeDocument().ActiveObject)");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')", App::Part::BaseplaneTypes[2]);
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(0,1,0),90))");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().addObject('App::Plane','%s')", App::Part::BaseplaneTypes[2]);
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Placement = App.Placement(App.Vector(),App.Rotation(App.Vector(1,1,1),120))");
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().ActiveObject.Label = '%s'", QObject::tr("YZ-Plane").toStdString().c_str());
Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(App.activeDocument().ActiveObject)", part->getNameInDocument());
//Gui::Command::doCommand(Gui::Command::Doc,"OGroup.addObject(App.activeDocument().ActiveObject)");
//Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(OGroup)", part->getNameInDocument());
//Gui::Command::doCommand(Gui::Command::Doc,"App.activeDocument().%s.addObject(OGroup)", part->getNameInDocument());
// TODO: Fold the group (is that possible through the Python interface?)
}

View File

@ -56,11 +56,6 @@ public:
virtual bool doubleClicked(void);
std::vector<std::string> getDisplayModes(void) const;
void hide(void);
void show(void);
bool isShow(void) const;
virtual bool onDelete(const std::vector<std::string> &);
/// get called if the user hover over a object in the tree
@ -74,6 +69,7 @@ protected:
/// get called by the container whenever a property has been changed
void onChanged(const App::Property* prop);
void getViewProviders(std::vector<ViewProviderDocumentObject*>&) const;
void onObjectChanged(const App::DocumentObject&, const App::Property&);
private:

View File

@ -43,6 +43,7 @@
#include <Inventor/nodes/SoMaterial.h>
#include <Inventor/nodes/SoAnnotation.h>
#include <Inventor/details/SoLineDetail.h>
#include <Inventor/nodes/SoAsciiText.h>
#include "ViewProviderPlane.h"
#include "SoFCSelection.h"
#include "Application.h"
@ -96,6 +97,16 @@ ViewProviderPlane::ViewProviderPlane()
pLines->ref();
pLines->coordIndex.setNum(6);
pLines->coordIndex.setValues(0, 6, lines);
pFont = new SoFont();
pFont->size.setValue(Size.getValue()/10.);
pTranslation = new SoTranslation();
pTranslation->translation.setValue(SbVec3f(-1,9./10.,0));
pText = new SoAsciiText();
pText->width.setValue(-1);
sPixmap = "view-measurement";
}
@ -118,6 +129,8 @@ void ViewProviderPlane::onChanged(const App::Property* prop)
};
pCoords->point.setValues(0, 4, verts);
pFont->size.setValue(Size.getValue()/10.);
pTranslation->translation.setValue(SbVec3f(-size,size*9./10.,0));
}
else
ViewProviderGeometryObject::onChanged(prop);
@ -144,27 +157,29 @@ void ViewProviderPlane::attach(App::DocumentObject* pcObject)
SoAnnotation *lineSep = new SoAnnotation();
SoAutoZoomTranslation *zoom = new SoAutoZoomTranslation;
SoDrawStyle* style = new SoDrawStyle();
style->lineWidth = 1.0f;
SoMaterialBinding* matBinding = new SoMaterialBinding;
matBinding->value = SoMaterialBinding::PER_FACE;
lineSep->addChild(zoom);
lineSep->addChild(style);
lineSep->addChild(matBinding);
lineSep->addChild(pMat);
lineSep->addChild(pCoords);
lineSep->addChild(pLines);
lineSep->addChild(pFont);
pText->string.setValue(SbString(pcObject->Label.getValue()));
lineSep->addChild(pTranslation);
lineSep->addChild(pText);
addDisplayMaskMode(lineSep, "Base");
}
void ViewProviderPlane::updateData(const App::Property* prop)
{
pText->string.setValue(SbString(pcObject->Label.getValue()));
ViewProviderGeometryObject::updateData(prop);
}

View File

@ -35,6 +35,8 @@ class SoCoordinate3;
class SoIndexedLineSet;
class SoEventCallback;
class SoMaterial;
class SoAsciiText;
class SoFont;
namespace Gui
{
@ -49,7 +51,7 @@ public:
ViewProviderPlane(void);
virtual ~ViewProviderPlane();
App::PropertyFloat Size;
App::PropertyFloat Size;
void attach(App::DocumentObject *);
void updateData(const App::Property*);
@ -71,6 +73,9 @@ private:
SoCoordinate3 * pCoords;
SoMaterial * pMat;
SoIndexedLineSet * pLines;
SoAsciiText * pText;
SoFont * pFont;
SoTranslation * pTranslation;
};
} //namespace Gui