diff --git a/src/Gui/ViewProviderGeoFeatureGroup.cpp b/src/Gui/ViewProviderGeoFeatureGroup.cpp index e039931a4..0a8af28c3 100644 --- a/src/Gui/ViewProviderGeoFeatureGroup.cpp +++ b/src/Gui/ViewProviderGeoFeatureGroup.cpp @@ -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 ViewProviderGeoFeatureGroup::getDisplayModes(void) const +{ + // get the modes of the father + std::vector StrList = ViewProviderGeometryObject::getDisplayModes(); + + // add your own modes + StrList.push_back("Part"); + + return StrList; +} // Python feature ----------------------------------------------------------------------- diff --git a/src/Gui/ViewProviderGeoFeatureGroup.h b/src/Gui/ViewProviderGeoFeatureGroup.h index f1355154b..393b564e5 100644 --- a/src/Gui/ViewProviderGeoFeatureGroup.h +++ b/src/Gui/ViewProviderGeoFeatureGroup.h @@ -43,8 +43,12 @@ public: virtual std::vector claimChildren(void)const; virtual std::vector 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 getDisplayModes(void) const; virtual bool onDelete(const std::vector &); @@ -52,8 +56,9 @@ public: //virtual bool allowDrop(const std::vector &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos); /// get called if the user drops some objects //virtual void drop(const std::vector &objList,Qt::KeyboardModifiers keys,Qt::MouseButtons mouseBts,const QPoint &pos); - - + +protected: + SoGroup *pcGroupChildren; }; typedef ViewProviderPythonFeatureT ViewProviderGeoFeatureGroupPython; diff --git a/src/Gui/ViewProviderPart.cpp b/src/Gui/ViewProviderPart.cpp index 6b16fe0d5..06eb3e8ad 100644 --- a/src/Gui/ViewProviderPart.cpp +++ b/src/Gui/ViewProviderPart.cpp @@ -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 +#include +#include 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(pcObject); + if(static_cast(pcObject)->hasObject(&obj) && obj.getTypeId() != App::Plane::getClassTypeId()) { + + View3DInventorViewer* viewer = static_cast(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 planes = part->getObjectsOfType(App::Plane::getClassTypeId()); + for (std::vector::const_iterator p = planes.begin(); p != planes.end(); p++) { + + Gui::ViewProviderPlane* vp = dynamic_cast(Gui::Application::Instance->getViewProvider(*p)); + if (strcmp(App::Part::BaseplaneTypes[0], dynamic_cast(*p)->getNameInDocument()) == 0) { + + Base::Placement cpl = dynamic_cast(*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(*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(*p)->getNameInDocument()) == 0) { + + Base::Placement cpl = dynamic_cast(*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(*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(*p)->getNameInDocument()) == 0) { + + Base::Placement cpl = dynamic_cast(*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(*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 ViewProviderPart::getDisplayModes(void) const -{ - // empty - return std::vector(); -} - bool ViewProviderPart::onDelete(const std::vector &) { //Gui::Command::doCommand(Gui::Command::Doc,"App.getDocument(\"%s\").getObject(\"%s\").removeObjectsFromDocument()" @@ -104,22 +159,6 @@ bool ViewProviderPart::onDelete(const std::vector &) 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?) } diff --git a/src/Gui/ViewProviderPart.h b/src/Gui/ViewProviderPart.h index 8b0d361f0..c936993ac 100644 --- a/src/Gui/ViewProviderPart.h +++ b/src/Gui/ViewProviderPart.h @@ -56,11 +56,6 @@ public: virtual bool doubleClicked(void); - std::vector getDisplayModes(void) const; - void hide(void); - void show(void); - bool isShow(void) const; - virtual bool onDelete(const std::vector &); /// 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&) const; + void onObjectChanged(const App::DocumentObject&, const App::Property&); private: diff --git a/src/Gui/ViewProviderPlane.cpp b/src/Gui/ViewProviderPlane.cpp index 9e60c2a9c..6a6d28dd0 100644 --- a/src/Gui/ViewProviderPlane.cpp +++ b/src/Gui/ViewProviderPlane.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #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); } diff --git a/src/Gui/ViewProviderPlane.h b/src/Gui/ViewProviderPlane.h index 5547cc5d6..cc9d6bbf1 100644 --- a/src/Gui/ViewProviderPlane.h +++ b/src/Gui/ViewProviderPlane.h @@ -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