From: vsv Date: Thu, 17 Jul 2014 13:29:59 +0000 (+0400) Subject: Create sketch with new model architecture X-Git-Tag: V_0.4.4~172^2~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=bbd1c59b9adc714c5d7ad17b3dc496cf1091c549;p=modules%2Fshaper.git Create sketch with new model architecture --- diff --git a/src/GeomAPI/GeomAPI_AISObject.cpp b/src/GeomAPI/GeomAPI_AISObject.cpp index 5ed7c01d1..b2bb96faf 100644 --- a/src/GeomAPI/GeomAPI_AISObject.cpp +++ b/src/GeomAPI/GeomAPI_AISObject.cpp @@ -29,6 +29,9 @@ const int CONSTRAINT_TEXT_SELECTION_TOLERANCE = 20; /// the text selection toler // Initialization of color constants int Colors::COLOR_BROWN = Quantity_NOC_BROWN; +int Colors::COLOR_RED = Quantity_NOC_RED; +int Colors::COLOR_GREEN = Quantity_NOC_GREEN; +int Colors::COLOR_BLUE = Quantity_NOC_BLUE1; GeomAPI_AISObject::GeomAPI_AISObject() diff --git a/src/GeomAPI/GeomAPI_AISObject.h b/src/GeomAPI/GeomAPI_AISObject.h index d3f238591..afd7ee95f 100644 --- a/src/GeomAPI/GeomAPI_AISObject.h +++ b/src/GeomAPI/GeomAPI_AISObject.h @@ -18,6 +18,9 @@ class GeomAPI_Shape; struct GEOMAPI_EXPORT Colors { static int COLOR_BROWN; + static int COLOR_RED; + static int COLOR_GREEN; + static int COLOR_BLUE; }; /** \class GeomAPI_AISObject diff --git a/src/ModuleBase/ModuleBase_ViewerPrs.h b/src/ModuleBase/ModuleBase_ViewerPrs.h index 4ef5e5bad..a365c753a 100644 --- a/src/ModuleBase/ModuleBase_ViewerPrs.h +++ b/src/ModuleBase/ModuleBase_ViewerPrs.h @@ -10,6 +10,7 @@ #include #include #include +#include #include @@ -59,18 +60,24 @@ public: /// \return a shape instance const TopoDS_Shape& shape() const { return myShape; } + void setInteractive(const Handle(AIS_InteractiveObject)& theIO) { myInteractive = theIO; } + + Handle(AIS_InteractiveObject) interactive() const { return myInteractive; } + bool operator==(const ModuleBase_ViewerPrs& thePrs) { bool aResult = (myResult.get() == thePrs.object().get()); bool aOwner = (myOwner.Access() == thePrs.owner().Access()); bool aShape = myShape.IsEqual(thePrs.shape()); - return aResult && aOwner && aShape; + bool aIO = myInteractive == thePrs.interactive(); + return aResult && aOwner && aShape && aIO; } private: ObjectPtr myResult; /// the feature Handle(SelectMgr_EntityOwner) myOwner; /// the selection owner TopoDS_Shape myShape; /// the shape + Handle(AIS_InteractiveObject) myInteractive; }; #endif diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index fc2ffb51b..4999e4f53 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -46,15 +46,26 @@ #include #include +#include #include #include #include +#include +#include + #ifdef _DEBUG #include #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) { @@ -212,14 +223,26 @@ void PartSet_Module::onMouseReleased(QMouseEvent* theEvent) { PartSet_OperationSketchBase* aPreviewOp = dynamic_cast( myWorkshop->operationMgr()->currentOperation()); - if (aPreviewOp) - { + if (aPreviewOp) { XGUI_Selection* aSelection = myWorkshop->selector()->selection(); // Initialise operation with preliminary selection std::list aSelected = aSelection->getSelected(); std::list aHighlighted = aSelection->getHighlighted(); - aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted); + 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 + aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted); } } @@ -257,6 +280,7 @@ void PartSet_Module::onMouseDoubleClick(QMouseEvent* theEvent) void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ) { + erasePlanes(); myWorkshop->viewer()->setViewProjection(theX, theY, theZ); myWorkshop->actionsMgr()->update(); @@ -444,6 +468,53 @@ 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, const bool isUpdateViewer) { @@ -461,9 +532,9 @@ void PartSet_Module::visualizePreview(FeaturePtr theFeature, bool isDisplay, boost::shared_ptr aSPFeature = boost::dynamic_pointer_cast(theFeature); if (aSPFeature) { + showPlanes(); //boost::shared_ptr anAIS = // aSPFeature->getAISObject(aDisplayer->getAISObject(aResult)); - aDisplayer->display(aSPFeature, false); //aDisplayer->redisplay(aResult, anAIS, false); } } @@ -478,11 +549,11 @@ void PartSet_Module::activateFeature(FeaturePtr theFeature, const bool isUpdateV { ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); - if (aPreviewOp) { +/* TODO if (aPreviewOp) { XGUI_Displayer* aDisplayer = myWorkshop->displayer(); aDisplayer->activateInLocalContext(theFeature->firstResult(), aPreviewOp->getSelectionModes(theFeature), isUpdateViewer); - } + }*/ } void PartSet_Module::updateCurrentPreview(const std::string& theCmdId) diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 4133472f1..83bb0b2d0 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -21,6 +21,7 @@ class PartSet_Listener; class ModelAPI_Feature; class XGUI_ViewerPrs; class ModuleBase_Operation; +class GeomAPI_AISObject; class PARTSET_EXPORT PartSet_Module: public ModuleBase_IModule { @@ -156,11 +157,20 @@ 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_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index 64ea866aa..c209af34b 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -37,6 +37,7 @@ using namespace std; + PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId, QObject* theParent) : PartSet_OperationSketchBase(theId, theParent) @@ -75,15 +76,7 @@ void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_Vie const std::list& theSelected, const std::list& theHighlighted) { - if (!hasSketchPlane()) { - if (!theHighlighted.empty()) { - ModuleBase_ViewerPrs aPrs = theHighlighted.front(); - const TopoDS_Shape& aShape = aPrs.shape(); - if (!aShape.IsNull()) - setSketchPlane(aShape); - } - } - else { + if (hasSketchPlane()){ // if shift button is pressed and there are some already selected objects, the operation should // not be started. We just want to combine some selected objects. bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier); @@ -109,9 +102,7 @@ void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_Vi const std::list& theSelected, const std::list& theHighlighted) { - if (!hasSketchPlane()) { - } - else { + if (hasSketchPlane()) { /// TODO: OCC bug: 25034 - the highlighted list should be filled not only for AIS_Shape /// but for other IO, for example constraint dimensions. /// It is empty and we have to use the process mouse release to start edition operation @@ -169,6 +160,7 @@ bool PartSet_OperationSketch::isNestedOperationsEnabled() const return hasSketchPlane(); } + void PartSet_OperationSketch::startOperation() { PartSet_OperationSketchBase::startOperation(); diff --git a/src/PartSet/PartSet_OperationSketch.h b/src/PartSet/PartSet_OperationSketch.h index bf8694bb5..826baf39d 100644 --- a/src/PartSet/PartSet_OperationSketch.h +++ b/src/PartSet/PartSet_OperationSketch.h @@ -86,6 +86,10 @@ public: /// \return the boolean value whether the sketch is set bool hasSketchPlane() const; + /// Set the plane to the current sketch + /// \param theShape the shape + void setSketchPlane(const TopoDS_Shape& theShape); + signals: /// signal about the sketch plane is selected /// \param theX the value in the X direction of the plane @@ -100,10 +104,6 @@ protected: /// Default impl calls corresponding slot and commits immediately. virtual void startOperation(); - /// Set the plane to the current sketch - /// \param theShape the shape - void setSketchPlane(const TopoDS_Shape& theShape); - private: std::list myFeatures; ///< the features to apply the edit operation }; diff --git a/src/SketchPlugin/SketchPlugin_Feature.h b/src/SketchPlugin/SketchPlugin_Feature.h index 6f1b3a66c..7bd7ac8d7 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.h +++ b/src/SketchPlugin/SketchPlugin_Feature.h @@ -23,10 +23,6 @@ class Handle_AIS_InteractiveObject; class SketchPlugin_Feature: public ModelAPI_Feature { public: - /// Returns the AIS preview - SKETCHPLUGIN_EXPORT virtual boost::shared_ptr getAISObject( - boost::shared_ptr thePrevious) = 0; - /// Simple creation of interactive object by the result of the object static boost::shared_ptr simpleAISObject( boost::shared_ptr theRes, boost::shared_ptr thePrevious); diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index dbfb24782..1f0e100ac 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -15,14 +15,8 @@ #include -const int SKETCH_PLANE_COLOR = Colors::COLOR_BROWN; /// the plane edge color -const double SKETCH_WIDTH = 4.0; /// the plane edge width - using namespace std; -// face of the square-face displayed for selection of general plane -const double PLANE_SIZE = 200; - SketchPlugin_Sketch::SketchPlugin_Sketch() { } @@ -38,19 +32,6 @@ void SketchPlugin_Sketch::initAttributes() void SketchPlugin_Sketch::execute() { - if (!isPlaneSet()) { - 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); - boost::shared_ptr aConstr = - document()->createConstruction(data()); - aConstr->setShape(aCompound); - setResult(aConstr); - return; - } if (!data()->isValid()) return ; boost::shared_ptr aRefList = @@ -97,32 +78,12 @@ void SketchPlugin_Sketch::execute() setResult(aConstr); } -boost::shared_ptr SketchPlugin_Sketch::getAISObject( - boost::shared_ptr thePrevious) -{ - boost::shared_ptr aResult = simpleAISObject(firstResult(), thePrevious); - aResult->setColor(SKETCH_PLANE_COLOR); - aResult->setWidth(SKETCH_WIDTH); - //anAIS->Redisplay(); - return aResult; -} - const void SketchPlugin_Sketch::addSub(const FeaturePtr& theFeature) { boost::dynamic_pointer_cast(theFeature)->setSketch(this); data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->append(theFeature); } -void SketchPlugin_Sketch::addPlane(double theX, double theY, double theZ, - std::list >& theShapes) const -{ - 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::to3D(const double theX, const double theY) { boost::shared_ptr aC = diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index 66f96bf4f..4fd2a58eb 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -9,14 +9,13 @@ #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, public GeomAPI_IPresentable +class SketchPlugin_Sketch: public SketchPlugin_Feature { public: /// Sketch feature kind @@ -66,10 +65,6 @@ public: /// Request for initialization of data model of the feature: adding all attributes SKETCHPLUGIN_EXPORT virtual void initAttributes(); - /// Returns the AIS preview - SKETCHPLUGIN_EXPORT virtual boost::shared_ptr getAISObject( - boost::shared_ptr thePrevious); - /// Adds sub-feature of the higher level feature (sub-element of the sketch) /// \param theFeature sub-feature SKETCHPLUGIN_EXPORT virtual const void addSub( @@ -102,8 +97,8 @@ protected: /// \param theY the Y normal value /// \param theZ the Z normal value /// \param theShapes the list of result shapes - void addPlane(double theX, double theY, double theZ, - std::list >& theShapes) const; + //void addPlane(double theX, double theY, double theZ, + // std::list >& theShapes) const; /// Checks whether the plane is set in the sketch. /// \returns the boolean state diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index e013befb7..92ae9d2a4 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -90,7 +90,6 @@ void XGUI_Displayer::erase(ObjectPtr theObject, const bool isUpdateViewer) Handle(AIS_InteractiveObject) anAIS = anObject->impl(); if (!anAIS.IsNull()) { aContext->Erase(anAIS, isUpdateViewer); - } } myResult2AISObjectMap.erase(theObject); @@ -344,3 +343,22 @@ Handle(AIS_InteractiveContext) XGUI_Displayer::AISContext() const { return myWorkshop->viewer()->AISContext(); } + + +void XGUI_Displayer::display(boost::shared_ptr theAIS, bool isUpdate) +{ + Handle(AIS_InteractiveContext) aContext = AISContext(); + Handle(AIS_InteractiveObject) anAISIO = theAIS->impl(); + if (!anAISIO.IsNull()) + aContext->Display(anAISIO, isUpdate); +} + +void XGUI_Displayer::erase(boost::shared_ptr theAIS, const bool isUpdate) +{ + Handle(AIS_InteractiveContext) aContext = AISContext(); + Handle(AIS_InteractiveObject) anAISIO = theAIS->impl(); + if (!anAISIO.IsNull()) { + aContext->Remove(anAISIO, isUpdate); + } +} + diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index 9304bae9b..df65443a8 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -57,6 +57,9 @@ public: /// Returns true if the Feature succesfully displayed void display(ObjectPtr theObject, bool isUpdateViewer = true); + /// Display the given AIS object. To hide this object use corresponde erase method + void display(boost::shared_ptr theAIS, bool isUpdate = true); + /// Redisplay the shape and activate selection of sub-shapes /// \param theFeature a feature instance /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly @@ -89,6 +92,9 @@ public: /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly void erase(ObjectPtr theObject, const bool isUpdateViewer = true); + /// Erase the given AIS object displayed by corresponded display method + void erase(boost::shared_ptr theAIS, const bool isUpdate = true); + /// Erase all presentations /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly //void EraseAll(const bool isUpdateViewer = true); diff --git a/src/XGUI/XGUI_Selection.cpp b/src/XGUI/XGUI_Selection.cpp index 8e4636fb9..b42f8c4b9 100644 --- a/src/XGUI/XGUI_Selection.cpp +++ b/src/XGUI/XGUI_Selection.cpp @@ -24,21 +24,28 @@ std::list XGUI_Selection::getSelected(int theShapeTypeToSk { std::set aPrsFeatures; std::list aPresentations; + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected()) { - Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive(); - TopoDS_Shape aShape = aContext->SelectedShape(); + ModuleBase_ViewerPrs aPrs; - if (theShapeTypeToSkip >= 0 && !aShape.IsNull() && aShape.ShapeType() == theShapeTypeToSkip) - continue; - - ObjectPtr aFeature = myWorkshop->displayer()->getObject(anIO); - if (aPrsFeatures.find(aFeature) != aPrsFeatures.end()) - continue; + Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive(); + aPrs.setInteractive(anIO); + + ObjectPtr aFeature = aDisplayer->getObject(anIO); + if (aPrsFeatures.find(aFeature) == aPrsFeatures.end()) { + aPrs.setFeature(aFeature); + aPrsFeatures.insert(aFeature); + } + if (aContext->HasOpenedContext()) { + TopoDS_Shape aShape = aContext->SelectedShape(); + if (!aShape.IsNull() && (aShape.ShapeType() != theShapeTypeToSkip)) + aPrs.setShape(aShape); + } Handle(SelectMgr_EntityOwner) anOwner = aContext->SelectedOwner(); - aPresentations.push_back(ModuleBase_ViewerPrs(aFeature, aShape, anOwner)); - aPrsFeatures.insert(aFeature); + aPrs.setOwner(anOwner); + aPresentations.push_back(aPrs); } return aPresentations; } @@ -47,21 +54,26 @@ std::list XGUI_Selection::getHighlighted(int theShapeTypeT { std::set aPrsFeatures; std::list aPresentations; + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) { + ModuleBase_ViewerPrs aPrs; Handle(AIS_InteractiveObject) anIO = aContext->DetectedInteractive(); - TopoDS_Shape aShape = aContext->DetectedShape(); - if (theShapeTypeToSkip >= 0 && !aShape.IsNull() && aShape.ShapeType() == theShapeTypeToSkip) - continue; - - ObjectPtr aResult = myWorkshop->displayer()->getObject(anIO); - if (aPrsFeatures.find(aResult) != aPrsFeatures.end()) - continue; - aPresentations.push_back(ModuleBase_ViewerPrs(aResult, aShape, NULL)); - aPrsFeatures.insert(aResult); + aPrs.setInteractive(anIO); + + ObjectPtr aResult = aDisplayer->getObject(anIO); + if (aPrsFeatures.find(aResult) == aPrsFeatures.end()) { + aPrs.setFeature(aResult); + aPrsFeatures.insert(aResult); + } + if (aContext->HasOpenedContext()) { + TopoDS_Shape aShape = aContext->DetectedShape(); + if (!aShape.IsNull() && aShape.ShapeType() != theShapeTypeToSkip) + aPrs.setShape(aShape); + } + aPresentations.push_back(aPrs); } - return aPresentations; }