From 09360d321e48c3749afa582c0958a28ea7bf9200 Mon Sep 17 00:00:00 2001 From: vsv Date: Mon, 21 Jul 2014 18:44:51 +0400 Subject: [PATCH] Restore old planes selection definition --- src/FeaturesPlugin/FeaturesPlugin_Extrusion.h | 6 +- src/PartSet/PartSet_Listener.cpp | 3 +- src/PartSet/PartSet_Module.cpp | 98 +++---------------- src/PartSet/PartSet_Module.h | 13 +-- .../PartSet_OperationFeatureCreate.cpp | 6 +- src/PartSet/PartSet_OperationSketch.cpp | 9 +- src/PartSet/PartSet_OperationSketch.h | 2 +- src/SketchPlugin/SketchPlugin_Arc.h | 3 +- src/SketchPlugin/SketchPlugin_Circle.h | 3 +- src/SketchPlugin/SketchPlugin_Sketch.cpp | 40 ++++++++ src/SketchPlugin/SketchPlugin_Sketch.h | 7 +- src/XGUI/XGUI_Displayer.cpp | 58 ++++++----- 12 files changed, 117 insertions(+), 131 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h index c83bead92..4e92bd7cb 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h @@ -20,19 +20,19 @@ public: /// attribute name of referenced face inline static const std::string& FACE_ID() { - static const std::string MY_FACE_ID("FeaturesPlugin_Extrusion::FACE_ID()"); + static const std::string MY_FACE_ID("extrusion_face"); return MY_FACE_ID; } /// attribute name of extrusion size inline static const std::string& SIZE_ID() { - static const std::string MY_SIZE_ID("FeaturesPlugin_Extrusion::SIZE_ID()"); + static const std::string MY_SIZE_ID("extrusion_size"); return MY_SIZE_ID; } /// attribute name of reverse direction inline static const std::string& REVERSE_ID() { - static const std::string MY_REVERSE_ID("FeaturesPlugin_Extrusion::REVERSE_ID()"); + static const std::string MY_REVERSE_ID("extrusion_reverse"); return MY_REVERSE_ID; } diff --git a/src/PartSet/PartSet_Listener.cpp b/src/PartSet/PartSet_Listener.cpp index 84db77027..af017fbba 100644 --- a/src/PartSet/PartSet_Listener.cpp +++ b/src/PartSet/PartSet_Listener.cpp @@ -50,9 +50,8 @@ void PartSet_Listener::processEvent(const Events_Message* theMessage) if (aFeature) { if (myModule->workshop()->displayer()->isVisible(aFeature->firstResult()) || aType == EVENT_OBJECT_CREATED) { - myModule->visualizePreview(aFeature, true, false); - //if (aType == EVENT_OBJECT_CREATED) myModule->activateFeature(aFeature, true); + // TODO myModule->visualizePreview(aFeature, true, false); } } } diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index ad4d26324..757d759c3 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -60,12 +60,6 @@ #endif -//const int SKETCH_PLANE_COLOR = Colors::COLOR_BROWN; /// the plane edge color -const double SKETCH_WIDTH = 4.0; /// the plane edge width -// face of the square-face displayed for selection of general plane -const double PLANE_SIZE = 200; - - /*!Create and return new instance of XGUI_Module*/ extern "C" PARTSET_EXPORT ModuleBase_IModule* createModule(XGUI_Workshop* theWshop) { @@ -229,21 +223,7 @@ void PartSet_Module::onMouseReleased(QMouseEvent* theEvent) std::list aSelected = aSelection->getSelected(); std::list aHighlighted = aSelection->getHighlighted(); - PartSet_OperationSketch* aSketchOp = dynamic_cast(aPreviewOp); - if (aSketchOp) { - if ((!aSketchOp->hasSketchPlane()) && (aSelected.size() > 0)) { - Handle(AIS_InteractiveObject) aAIS = aSelected.front().interactive(); - if ((aAIS == myXPlane->impl()) || - (aAIS == myYPlane->impl()) || - (aAIS == myZPlane->impl()) ) { - - Handle(AIS_Shape) aAISShape = Handle(AIS_Shape)::DownCast(aAIS); - aSketchOp->setSketchPlane(aAISShape->Shape()); - } - } else - aSketchOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted); - } else - aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted); + aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted); } } @@ -281,7 +261,7 @@ void PartSet_Module::onMouseDoubleClick(QMouseEvent* theEvent) void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ) { - erasePlanes(); + //erasePlanes(); myWorkshop->viewer()->setViewProjection(theX, theY, theZ); myWorkshop->actionsMgr()->update(); @@ -364,7 +344,10 @@ void PartSet_Module::onCloseLocalContext() void PartSet_Module::onFeatureConstructed(FeaturePtr theFeature, int theMode) { - bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide; + ModelAPI_EventCreator::get()->sendUpdated(theFeature, + Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)); + +/* bool isDisplay = theMode != PartSet_OperationSketchBase::FM_Hide; // TODO visualizePreview(theFeature, isDisplay, false); if (!isDisplay) { ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation(); @@ -377,15 +360,15 @@ void PartSet_Module::onFeatureConstructed(FeaturePtr theFeature, int theMode) std::list::const_iterator anIt = aList.begin(), aLast = aList.end(); - for (; anIt != aLast; anIt++) - visualizePreview((*anIt), false, false); - aDisplayer->updateViewer(); + //TODO for (; anIt != aLast; anIt++) + // visualizePreview((*anIt), false, false); + //aDisplayer->updateViewer(); } } if (theMode == PartSet_OperationSketchBase::FM_Activation || theMode == PartSet_OperationSketchBase::FM_Deactivation) - activateFeature(theFeature, true); + activateFeature(theFeature, true);*/ } ModuleBase_Operation* PartSet_Module::createOperation(const std::string& theCmdId, @@ -473,54 +456,8 @@ void PartSet_Module::sendOperation(ModuleBase_Operation* theOperation) Events_Loop::loop()->send(aMessage); } -boost::shared_ptr getPlane(double theX, double theY, double theZ) -{ - boost::shared_ptr anOrigin(new GeomAPI_Pnt(0, 0, 0)); - boost::shared_ptr aNormal(new GeomAPI_Dir(theX, theY, theZ)); - return GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal, PLANE_SIZE); -} - -void PartSet_Module::showPlanes() -{ - XGUI_Displayer* aDisplayer = myWorkshop->displayer(); - // Show selection planes - if (!myXPlane) { - boost::shared_ptr aPlaneX = getPlane(1, 0, 0); - myXPlane = boost::shared_ptr(new GeomAPI_AISObject()); - myXPlane->createShape(aPlaneX); - myXPlane->setColor(Colors::COLOR_RED); - myXPlane->setWidth(SKETCH_WIDTH); - } - if (!myYPlane) { - boost::shared_ptr aPlaneY = getPlane(0, 1, 0); - myYPlane = boost::shared_ptr(new GeomAPI_AISObject()); - myYPlane->createShape(aPlaneY); - myYPlane->setColor(Colors::COLOR_GREEN); - myYPlane->setWidth(SKETCH_WIDTH); - } - if (!myZPlane) { - boost::shared_ptr aPlaneZ = getPlane(0, 0, 1); - myZPlane = boost::shared_ptr(new GeomAPI_AISObject()); - myZPlane->createShape(aPlaneZ); - myZPlane->setColor(Colors::COLOR_BLUE); - myZPlane->setWidth(SKETCH_WIDTH); - } - aDisplayer->display(myXPlane, false); - aDisplayer->display(myYPlane, false); - aDisplayer->display(myZPlane, false); - aDisplayer->updateViewer(); -} - -void PartSet_Module::erasePlanes() -{ - XGUI_Displayer* aDisplayer = myWorkshop->displayer(); - aDisplayer->erase(myXPlane, false); - aDisplayer->erase(myYPlane, false); - aDisplayer->erase(myZPlane, false); - aDisplayer->updateViewer(); -} -void PartSet_Module::visualizePreview(FeaturePtr theFeature, bool isDisplay, +/*void PartSet_Module::visualizePreview(FeaturePtr theFeature, bool isDisplay, const bool isUpdateViewer) { ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); @@ -547,19 +484,16 @@ void PartSet_Module::visualizePreview(FeaturePtr theFeature, bool isDisplay, if (isUpdateViewer) aDisplayer->updateViewer(); -} +}*/ void PartSet_Module::activateFeature(ObjectPtr theFeature, const bool isUpdateViewer) { ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); if (aPreviewOp) { - PartSet_OperationSketch* aOp = dynamic_cast(aPreviewOp); - if (!aOp) { - XGUI_Displayer* aDisplayer = myWorkshop->displayer(); - aDisplayer->activateInLocalContext(theFeature, aPreviewOp->getSelectionModes(theFeature), - isUpdateViewer); - } + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + aDisplayer->activateInLocalContext(theFeature, aPreviewOp->getSelectionModes(theFeature), + isUpdateViewer); } } @@ -588,7 +522,7 @@ void PartSet_Module::updateCurrentPreview(const std::string& theCmdId) boost::dynamic_pointer_cast(*anIt); if (!aSPFeature) continue; - visualizePreview((*anIt), true, false); + //visualizePreview((*anIt), true, false); aDisplayer->activateInLocalContext((*anIt)->firstResult(), aModes, false); } aDisplayer->updateViewer(); diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 49a41a9ec..ac90ea98a 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -56,8 +56,8 @@ public: /// \param theFeature the feature instance to be displayed /// \param isDisplay the state whether the presentation should be displayed or erased /// \param isUpdateViewer the flag whether the viewer should be updated - void visualizePreview(FeaturePtr theFeature, bool isDisplay, - const bool isUpdateViewer = true); + //void visualizePreview(FeaturePtr theFeature, bool isDisplay, + // const bool isUpdateViewer = true); /// Activates the feature in the displayer /// \param theFeature the feature instance to be displayed @@ -157,20 +157,11 @@ protected: //! Edits the feature void editFeature(FeaturePtr theFeature); - - //! Shopws working planes in viewer 3d - void showPlanes(); - void erasePlanes(); - private: XGUI_Workshop* myWorkshop; PartSet_Listener* myListener; std::map myFeaturesInFiles; - - boost::shared_ptr myXPlane; - boost::shared_ptr myYPlane; - boost::shared_ptr myZPlane; }; #endif diff --git a/src/PartSet/PartSet_OperationFeatureCreate.cpp b/src/PartSet/PartSet_OperationFeatureCreate.cpp index 44cf5e5a3..859dbc93f 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.cpp +++ b/src/PartSet/PartSet_OperationFeatureCreate.cpp @@ -146,11 +146,11 @@ void PartSet_OperationFeatureCreate::mouseReleased(QMouseEvent* theEvent, Handle } } ObjectPtr aFeature; - if (!theSelected.empty()) { +/* TODO if (!theSelected.empty()) { ModuleBase_ViewerPrs aPrs = theSelected.front(); aFeature = aPrs.object(); - } else - aFeature = feature(); // for the widget distance only + } else*/ + aFeature = feature(); // for the widget distance only bool isApplyed = setWidgetValue(aFeature, aX, anY); if (isApplyed) { diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index 88a0e156e..8d2b7e5fc 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -48,7 +48,7 @@ PartSet_OperationSketch::~PartSet_OperationSketch() { } -std::list PartSet_OperationSketch::getSelectionModes(FeaturePtr theFeature) const +std::list PartSet_OperationSketch::getSelectionModes(ObjectPtr theFeature) const { std::list aModes; if (!hasSketchPlane()) @@ -95,6 +95,13 @@ void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_Vie else myFeatures = theHighlighted; + } else { + if (!theHighlighted.empty()) { + ModuleBase_ViewerPrs aPrs = theHighlighted.front(); + const TopoDS_Shape& aShape = aPrs.shape(); + if (!aShape.IsNull()) + setSketchPlane(aShape); + } } } diff --git a/src/PartSet/PartSet_OperationSketch.h b/src/PartSet/PartSet_OperationSketch.h index 826baf39d..1cd920158 100644 --- a/src/PartSet/PartSet_OperationSketch.h +++ b/src/PartSet/PartSet_OperationSketch.h @@ -37,7 +37,7 @@ public: /// Returns the operation local selection mode /// \param theFeature the feature object to get the selection mode /// \return the selection mode - virtual std::list getSelectionModes(FeaturePtr theFeature) const; + virtual std::list getSelectionModes(ObjectPtr theFeature) const; /// Initializes the operation with previously created feature. It is used in sequental operations virtual void initFeature(FeaturePtr theFeature); diff --git a/src/SketchPlugin/SketchPlugin_Arc.h b/src/SketchPlugin/SketchPlugin_Arc.h index df87c1e3c..66da16cfe 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.h +++ b/src/SketchPlugin/SketchPlugin_Arc.h @@ -8,12 +8,13 @@ #include "SketchPlugin.h" #include #include +#include /**\class SketchPlugin_Arc * \ingroup DataModel * \brief Feature for creation of the new arc of circle in PartSet. */ -class SketchPlugin_Arc: public SketchPlugin_Feature +class SketchPlugin_Arc: public SketchPlugin_Feature//, public GeomAPI_IPresentable { public: /// Arc feature kind diff --git a/src/SketchPlugin/SketchPlugin_Circle.h b/src/SketchPlugin/SketchPlugin_Circle.h index 43c2c982a..9d923654d 100644 --- a/src/SketchPlugin/SketchPlugin_Circle.h +++ b/src/SketchPlugin/SketchPlugin_Circle.h @@ -8,12 +8,13 @@ #include "SketchPlugin.h" #include #include +#include /**\class SketchPlugin_Circle * \ingroup DataModel * \brief Feature for creation of the new circle in PartSet. */ -class SketchPlugin_Circle: public SketchPlugin_Feature +class SketchPlugin_Circle: public SketchPlugin_Feature//, public GeomAPI_IPresentable { public: /// Circle feature kind diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 1f0e100ac..9cd5ccff4 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -17,6 +17,12 @@ using namespace std; +const int SKETCH_PLANE_COLOR = Colors::COLOR_BROWN; /// the plane edge color +const double SKETCH_WIDTH = 4.0; /// the plane edge width +// face of the square-face displayed for selection of general plane +const double PLANE_SIZE = 200; + + SketchPlugin_Sketch::SketchPlugin_Sketch() { } @@ -119,3 +125,37 @@ boost::shared_ptr SketchPlugin_Sketch::plane() return boost::shared_ptr(new GeomAPI_Pln(anOrigin->pnt(), aNorm->dir())); } + +void addPlane(double theX, double theY, double theZ, std::list >& theShapes) +{ + boost::shared_ptr anOrigin(new GeomAPI_Pnt(0, 0, 0)); + boost::shared_ptr aNormal(new GeomAPI_Dir(theX, theY, theZ)); + boost::shared_ptr aFace = + GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal, PLANE_SIZE); + theShapes.push_back(aFace); +} + +boost::shared_ptr SketchPlugin_Sketch:: + getAISObject(boost::shared_ptr thePrevious) +{ + boost::shared_ptr aNorm = + boost::dynamic_pointer_cast(data()->attribute(SketchPlugin_Sketch::NORM_ID())); + + if (!aNorm || (aNorm->x() == 0 && aNorm->y() == 0 && aNorm->z() == 0)) { + boost::shared_ptr aAIS = thePrevious; + if (!aAIS) { + std::list > aFaces; + + addPlane(1, 0, 0, aFaces); // YZ plane + addPlane(0, 1, 0, aFaces); // XZ plane + addPlane(0, 0, 1, aFaces); // XY plane + boost::shared_ptr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aFaces); + aAIS = boost::shared_ptr(new GeomAPI_AISObject()); + aAIS->createShape(aCompound); + aAIS->setColor(SKETCH_PLANE_COLOR); + aAIS->setWidth(SKETCH_WIDTH); + } + return aAIS; + } + return boost::shared_ptr(); +} diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index 4fd2a58eb..8a1d22db4 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -9,13 +9,14 @@ #include #include #include +#include #include /**\class SketchPlugin_Sketch * \ingroup DataModel * \brief Feature for creation of the new part in PartSet. */ -class SketchPlugin_Sketch: public SketchPlugin_Feature +class SketchPlugin_Sketch: public SketchPlugin_Feature, public GeomAPI_IPresentable { public: /// Sketch feature kind @@ -91,6 +92,10 @@ public: /// Returns the basis plane for the sketch boost::shared_ptr plane(); + + virtual boost::shared_ptr getAISObject( + boost::shared_ptr thePrevious); + protected: /// Creates a plane and append it to the list /// \param theX the X normal value diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index f124270b5..ed92f3845 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -48,17 +48,17 @@ void XGUI_Displayer::display(ObjectPtr theObject, bool isUpdateViewer) } else { boost::shared_ptr anAIS; - ResultPtr aResult = boost::dynamic_pointer_cast(theObject); - if (aResult) { - boost::shared_ptr aShapePtr = ModuleBase_Tools::shape(aResult); - if (aShapePtr) { - anAIS = boost::shared_ptr(new GeomAPI_AISObject()); - anAIS->createShape(aShapePtr); - } + GeomPresentablePtr aPrs = boost::dynamic_pointer_cast(theObject); + if (aPrs) { + anAIS = aPrs->getAISObject(boost::shared_ptr()); } else { - GeomPresentablePtr aPrs = boost::dynamic_pointer_cast(theObject); - if (aPrs) { - anAIS = aPrs->getAISObject(boost::shared_ptr()); + ResultPtr aResult = boost::dynamic_pointer_cast(theObject); + if (aResult) { + boost::shared_ptr aShapePtr = ModuleBase_Tools::shape(aResult); + if (aShapePtr) { + anAIS = boost::shared_ptr(new GeomAPI_AISObject()); + anAIS->createShape(aShapePtr); + } } } if (anAIS) @@ -131,23 +131,27 @@ void XGUI_Displayer::redisplay(ObjectPtr theObject, bool isUpdateViewer) if (!isVisible(theObject)) return; - ResultPtr aResult = boost::dynamic_pointer_cast(theObject); - if (aResult) { - boost::shared_ptr aShapePtr = ModuleBase_Tools::shape(aResult); - if (aShapePtr) { - boost::shared_ptr aAISObj = getAISObject(theObject); - Handle(AIS_Shape) aAISShape = Handle(AIS_Shape)::DownCast(aAISObj->impl()); - if (!aAISShape.IsNull()) { - aAISShape->Set(aShapePtr->impl()); - AISContext()->Redisplay(aAISShape, isUpdateViewer); - } + boost::shared_ptr aAISObj = getAISObject(theObject); + GeomPresentablePtr aPrs = boost::dynamic_pointer_cast(theObject); + if (aPrs) { + boost::shared_ptr aAIS_Obj = aPrs->getAISObject(aAISObj); + if (aAISObj && !aAIS_Obj) { + erase(theObject, isUpdateViewer); + return; } + Handle(AIS_InteractiveObject) aAISIO = aAIS_Obj->impl(); + AISContext()->Redisplay(aAISIO, isUpdateViewer); } else { - GeomPresentablePtr aPrs = boost::dynamic_pointer_cast(theObject); - if (aPrs) { - boost::shared_ptr aAISObj = aPrs->getAISObject(getAISObject(theObject)); - Handle(AIS_InteractiveObject) aAISIO = aAISObj->impl(); - AISContext()->Redisplay(aAISIO, isUpdateViewer); + ResultPtr aResult = boost::dynamic_pointer_cast(theObject); + if (aResult) { + boost::shared_ptr aShapePtr = ModuleBase_Tools::shape(aResult); + if (aShapePtr) { + Handle(AIS_Shape) aAISShape = Handle(AIS_Shape)::DownCast(aAISObj->impl()); + if (!aAISShape.IsNull()) { + aAISShape->Set(aShapePtr->impl()); + AISContext()->Redisplay(aAISShape, isUpdateViewer); + } + } } } } @@ -161,6 +165,10 @@ void XGUI_Displayer::activateInLocalContext(ObjectPtr theResult, aContext->ClearCurrents(false); aContext->OpenLocalContext(false/*use displayed objects*/, true/*allow shape decomposition*/); } +/* std::list::const_iterator anIt; + for (anIt = theModes.begin(); anIt != theModes.end(); anIt++) + aContext->ActivateStandardMode((TopAbs_ShapeEnum)(*anIt)); + */ // display or redisplay presentation Handle(AIS_InteractiveObject) anAIS; if (isVisible(theResult)) -- 2.39.2