From: nds Date: Mon, 5 May 2014 15:44:56 +0000 (+0400) Subject: refs #30 - Sketch base GUI: create, draw lines X-Git-Tag: V_0.2~88 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=eba34f3947483cd9a7a8f441af334fba01f36425;p=modules%2Fshaper.git refs #30 - Sketch base GUI: create, draw lines Edit line. --- diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index 3744b2d4c..2f4c40ba7 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -7,6 +7,7 @@ SET(PROJECT_HEADERS PartSet.h PartSet_Listener.h PartSet_Module.h + PartSet_OperationEditLine.h PartSet_OperationSketchBase.h PartSet_OperationSketch.h PartSet_OperationSketchLine.h @@ -16,6 +17,7 @@ SET(PROJECT_HEADERS SET(PROJECT_SOURCES PartSet_Listener.cpp PartSet_Module.cpp + PartSet_OperationEditLine.cpp PartSet_OperationSketchBase.cpp PartSet_OperationSketch.cpp PartSet_OperationSketchLine.cpp diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 4a0c54e5b..bb9556b44 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -105,34 +106,8 @@ void PartSet_Module::onFeatureTriggered() void PartSet_Module::launchOperation(const QString& theCmdId) { - std::string aStdCmdId = theCmdId.toStdString(); - std::string aPluginFileName = featureFile(aStdCmdId); - Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName); - aWdgReader.readAll(); - std::string aXmlCfg = aWdgReader.featureWidgetCfg(aStdCmdId); - std::string aDescription = aWdgReader.featureDescription(aStdCmdId); - ModuleBase_Operation* aPartSetOp; - if (theCmdId == "Sketch" ) { - aPartSetOp = new PartSet_OperationSketch(theCmdId, this); - } - else if(theCmdId == "SketchLine") { - ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); - boost::shared_ptr aSketchFeature; - if (anOperation) - aSketchFeature = anOperation->feature(); - aPartSetOp = new PartSet_OperationSketchLine(theCmdId, this, aSketchFeature); - } - else { - aPartSetOp = new ModuleBase_Operation(theCmdId, this); - } - aPartSetOp->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg)); - aPartSetOp->getDescription()->setDescription(QString::fromStdString(aDescription)); - - //TODO(sbh): Implement static method to extract event id [SEID] - static Events_ID aModuleEvent = Events_Loop::eventByName("PartSetModuleEvent"); - Config_PointerMessage aMessage(aModuleEvent, this); - aMessage.setPointer(aPartSetOp); - Events_Loop::loop()->send(aMessage); + ModuleBase_Operation* anOperation = createOperation(theCmdId); + sendOperation(anOperation); } void PartSet_Module::onOperationStarted() @@ -150,6 +125,9 @@ void PartSet_Module::onOperationStarted() if (aSketchOp) { connect(aSketchOp, SIGNAL(planeSelected(double, double, double)), this, SLOT(onPlaneSelected(double, double, double))); + connect(aSketchOp, SIGNAL(launchOperation(std::string, boost::shared_ptr)), + this, SLOT(onLaunchOperation(std::string, boost::shared_ptr))); + } } } @@ -172,7 +150,14 @@ void PartSet_Module::onSelectionChanged() if (aSelector) { NCollection_List aList; aSelector->selectedShapes(aList); - aPreviewOp->setSelectedShapes(aList); + + XGUI_Displayer* aDisplayer = myWorkshop->displayer(); + boost::shared_ptr aFeature; + if (!aList.IsEmpty()) { + const TopoDS_Shape& aShape = aList.First(); + aFeature = aDisplayer->GetFeature(aShape); + aPreviewOp->setSelected(aFeature, aShape); + } } } } @@ -225,7 +210,6 @@ void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ) if (anOperation) { PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); if (aPreviewOp) { - aPreviewOp->setEditMode(true); visualizePreview(aPreviewOp->feature(), false); } } @@ -233,6 +217,17 @@ void PartSet_Module::onPlaneSelected(double theX, double theY, double theZ) myWorkshop->actionsMgr()->setNestedActionsEnabled(true); } +void PartSet_Module::onLaunchOperation(std::string theName, boost::shared_ptr theFeature) +{ + ModuleBase_Operation* anOperation = createOperation(theName.c_str()); + PartSet_OperationSketchBase* aPreviewOp = dynamic_cast(anOperation); + if (aPreviewOp) + { + aPreviewOp->init(theFeature); + } + sendOperation(anOperation); +} + void PartSet_Module::onFeatureConstructed(boost::shared_ptr theFeature, int theMode) { @@ -240,6 +235,48 @@ void PartSet_Module::onFeatureConstructed(boost::shared_ptr th visualizePreview(theFeature, isDisplay); } +ModuleBase_Operation* PartSet_Module::createOperation(const QString& theCmdId) +{ + std::string aStdCmdId = theCmdId.toStdString(); + if (aStdCmdId == "EditLine") + aStdCmdId = "SketchLine"; + std::string aPluginFileName = featureFile(aStdCmdId); + Config_WidgetReader aWdgReader = Config_WidgetReader(aPluginFileName); + aWdgReader.readAll(); + std::string aXmlCfg = aWdgReader.featureWidgetCfg(aStdCmdId); + std::string aDescription = aWdgReader.featureDescription(aStdCmdId); + ModuleBase_Operation* anOperation; + if (theCmdId == "Sketch" ) { + anOperation = new PartSet_OperationSketch(theCmdId, this); + } + else if(theCmdId == "SketchLine" || theCmdId == "EditLine") { + ModuleBase_Operation* aCurOperation = myWorkshop->operationMgr()->currentOperation(); + boost::shared_ptr aSketchFeature; + if (aCurOperation) + aSketchFeature = aCurOperation->feature(); + if (theCmdId == "SketchLine") + anOperation = new PartSet_OperationSketchLine(theCmdId, this, aSketchFeature); + else + anOperation = new PartSet_OperationEditLine(theCmdId, this, aSketchFeature); + } + else { + anOperation = new ModuleBase_Operation(theCmdId, this); + } + anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg)); + anOperation->getDescription()->setDescription(QString::fromStdString(aDescription)); + + return anOperation; +} + +void PartSet_Module::sendOperation(ModuleBase_Operation* theOperation) +{ + //TODO(sbh): Implement static method to extract event id [SEID] + static Events_ID aModuleEvent = Events_Loop::eventByName("PartSetModuleEvent"); + Config_PointerMessage aMessage(aModuleEvent, this); + aMessage.setPointer(theOperation); + Events_Loop::loop()->send(aMessage); +} + void PartSet_Module::visualizePreview(boost::shared_ptr theFeature, bool isDisplay) { ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation(); diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 1f3197bd9..8f0a0b086 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -31,6 +31,8 @@ public: virtual QStringList nestedFeatures(QString theFeature); std::string featureFile(const std::string&); + /// Creates an operation and send it to loop + /// \param theCmdId the operation name virtual void launchOperation(const QString& theCmdId); /// Displays or erase the current operation preview, if it has it. @@ -69,11 +71,21 @@ public slots: /// \param theZ the Z projection value void onPlaneSelected(double theX, double theY, double theZ); + void onLaunchOperation(std::string theName, boost::shared_ptr theFeature); + /// SLOT, to visualize the feature in another local context mode /// \param theFeature the feature to be put in another local context mode /// \param theMode the mode appeared on the feature void onFeatureConstructed(boost::shared_ptr theFeature, int theMode); +protected: + /// Creates a new operation + /// \param theCmdId the operation name + ModuleBase_Operation* createOperation(const QString& theCmdId); + + /// Sends the operation + /// \param theOperation the operation + void sendOperation(ModuleBase_Operation* theOperation); private: XGUI_Workshop* myWorkshop; diff --git a/src/PartSet/PartSet_OperationEditLine.cpp b/src/PartSet/PartSet_OperationEditLine.cpp new file mode 100644 index 000000000..72020fb9a --- /dev/null +++ b/src/PartSet/PartSet_OperationEditLine.cpp @@ -0,0 +1,206 @@ +// File: PartSet_OperationEditLine.h +// Created: 05 May 2014 +// Author: Natalia ERMOLAEVA + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#ifdef _DEBUG +#include +#endif + +using namespace std; + +PartSet_OperationEditLine::PartSet_OperationEditLine(const QString& theId, + QObject* theParent, + boost::shared_ptr theFeature) +: PartSet_OperationSketchBase(theId, theParent), mySketch(theFeature) +{ +} + +PartSet_OperationEditLine::~PartSet_OperationEditLine() +{ +} + +bool PartSet_OperationEditLine::isGranted() const +{ + return true; +} + +std::list PartSet_OperationEditLine::getSelectionModes(boost::shared_ptr theFeature) const +{ + std::list aModes; + //if (theFeature != feature()) + // aModes.push_back(TopAbs_VERTEX); + return aModes; +} + +void PartSet_OperationEditLine::init(boost::shared_ptr theFeature) +{ + setFeature(theFeature); +} + +void PartSet_OperationEditLine::mouseReleased(const gp_Pnt& thePoint) +{ + /*switch (myPointSelectionMode) + { + case SM_FirstPoint: { + setLinePoint(thePoint, LINE_ATTR_START); + myPointSelectionMode = SM_SecondPoint; + } + break; + case SM_SecondPoint: { + setLinePoint(thePoint, LINE_ATTR_END); + myPointSelectionMode = SM_None; + } + break; + case SM_None: { + + } + break; + default: + break; + } +*/ +} + +void PartSet_OperationEditLine::mouseMoved(const gp_Pnt& thePoint) +{ +/* switch (myPointSelectionMode) + { + case SM_SecondPoint: + setLinePoint(thePoint, LINE_ATTR_END); + break; + case SM_None: { + boost::shared_ptr aPrevFeature = feature(); + // stop the last operation + commitOperation(); + document()->finishOperation(); + //emit changeSelectionMode(aPrevFeature, TopAbs_VERTEX); + // start a new operation + document()->startOperation(); + startOperation(); + // use the last point of the previous feature as the first of the new one + setLinePoint(aPrevFeature, LINE_ATTR_END, LINE_ATTR_START); + myPointSelectionMode = SM_SecondPoint; + + emit featureConstructed(aPrevFeature, FM_Deactivation); + } + break; + default: + break; + } +*/ +} + +void PartSet_OperationEditLine::keyReleased(const int theKey) +{ +/* switch (theKey) { + case Qt::Key_Escape: { + if (myPointSelectionMode != SM_None) + emit featureConstructed(feature(), FM_Abort); + abort(); + } + break; + case Qt::Key_Return: { + if (myPointSelectionMode != SM_None) { + emit featureConstructed(feature(), FM_Abort); + myPointSelectionMode = SM_FirstPoint; + document()->abortOperation(); + } + else + myPointSelectionMode = SM_FirstPoint; + } + break; + default: + break; + } + */ +} + +void PartSet_OperationEditLine::setSelected(boost::shared_ptr theFeature, + const TopoDS_Shape& theShape) +{ + if (theFeature == feature()) + return; + + commit(); + + if (theFeature) + emit launchOperation("EditLine", theFeature); +} + +void PartSet_OperationEditLine::startOperation() +{ + //PartSet_OperationSketchBase::startOperation(); + //myPointSelectionMode = SM_FirstPoint; +} + +void PartSet_OperationEditLine::stopOperation() +{ + PartSet_OperationSketchBase::stopOperation(); + //myPointSelectionMode = SM_None; +} + +boost::shared_ptr PartSet_OperationEditLine::createFeature() +{ + return boost::shared_ptr(); +} + +void PartSet_OperationEditLine::setLinePoint(const gp_Pnt& thePoint, + const std::string& theAttribute) +{ + boost::shared_ptr aData = feature()->data(); + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(theAttribute)); + + double aX = 0; + double anY = 0; + convertTo2D(thePoint, aX, anY); + aPoint->setValue(aX, anY); +} + +void PartSet_OperationEditLine::setLinePoint(boost::shared_ptr theSourceFeature, + const std::string& theSourceAttribute, + const std::string& theAttribute) +{ + boost::shared_ptr aData = theSourceFeature->data(); + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(theSourceAttribute)); + double aX = aPoint->x(); + double anY = aPoint->y(); + + aData = feature()->data(); + aPoint = boost::dynamic_pointer_cast(aData->attribute(theAttribute)); + aPoint->setValue(aX, anY); +} + +void PartSet_OperationEditLine::convertTo2D(const gp_Pnt& thePoint, double& theX, double& theY) +{ + if (!mySketch) + return; + + boost::shared_ptr anAttr; + boost::shared_ptr aData = mySketch->data(); + + boost::shared_ptr anOrigin = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_ORIGIN)); + + boost::shared_ptr aX = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRX)); + boost::shared_ptr anY = + boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRY)); + + gp_Pnt aVec(thePoint.X() - anOrigin->x(), thePoint.Y() - anOrigin->y(), thePoint.Z() - anOrigin->z()); + theX = aVec.X() * aX->x() + aVec.Y() * aX->y() + aVec.Z() * aX->z(); + theY = aVec.X() * anY->x() + aVec.Y() * anY->y() + aVec.Z() * anY->z(); +} diff --git a/src/PartSet/PartSet_OperationEditLine.h b/src/PartSet/PartSet_OperationEditLine.h new file mode 100644 index 000000000..5ce170bbc --- /dev/null +++ b/src/PartSet/PartSet_OperationEditLine.h @@ -0,0 +1,111 @@ +// File: PartSet_OperationEditLine.h +// Created: 05 May 2014 +// Author: Natalia ERMOLAEVA + +#ifndef PartSet_OperationEditLine_H +#define PartSet_OperationEditLine_H + +#include "PartSet.h" + +#include +#include + +/*! + \class PartSet_OperationEditLine + * \brief The operation for the sketch feature creation +*/ +class PARTSET_EXPORT PartSet_OperationEditLine : public PartSet_OperationSketchBase +{ + Q_OBJECT +public: + /// Constructor + /// \param theId the feature identifier + /// \param theParent the operation parent + /// \param theFeature the parent feature + PartSet_OperationEditLine(const QString& theId, QObject* theParent, + boost::shared_ptr theFeature); + /// Destructor + virtual ~PartSet_OperationEditLine(); + + /// Returns that this operator can be started above already running one. + /// The runned operation should be the sketch feature modified operation + virtual bool isGranted() const; + + /// Returns the operation local selection mode + /// \param theFeature the feature object to get the selection mode + /// \return the selection mode + virtual std::list getSelectionModes(boost::shared_ptr theFeature) const; + + /// Initializes some fields accorging to the feature + /// \param theFeature the feature + virtual void init(boost::shared_ptr theFeature); + + /// Gives the current selected objects to be processed by the operation + /// \param thePoint a point clicked in the viewer + virtual void mouseReleased(const gp_Pnt& thePoint); + /// Gives the current mouse point in the viewer + /// \param thePoint a point clicked in the viewer + virtual void mouseMoved(const gp_Pnt& thePoint); + /// Processes the key pressed in the view + /// \param theKey a key value + virtual void keyReleased(const int theKey); + + /// Gives the current selected objects to be processed by the operation + /// \param theFeature the selected feature + /// \param theShape the selected shape + virtual void setSelected(boost::shared_ptr theFeature, + const TopoDS_Shape& theShape); + +signals: + /// signal about the sketch plane is selected + /// \param theX the value in the X direction of the plane + /// \param theX the value in the Y direction value of the plane + /// \param theX the value in the Z direction of the plane + void localContextChanged(boost::shared_ptr theFeature, + int theMode); + +protected: + /// \brief Virtual method called when operation is started + /// Virtual method called when operation started (see start() method for more description) + /// After the parent operation body perform, set sketch feature to the created line feature + virtual void startOperation(); + + /// \brief Virtual method called when operation is started + /// Virtual method called when operation stopped - committed or aborted. + /// After the parent operation body perform, reset selection point mode of the operation + virtual void stopOperation(); + + /// Creates an operation new feature + /// Returns NULL feature. This is an operation of edition, not creation. + /// \returns the created feature + virtual boost::shared_ptr createFeature(); + +protected: + /// \brief Save the point to the line. + /// \param thePoint the 3D point in the viewer + /// \param theAttribute the start or end attribute of the line + void setLinePoint(const gp_Pnt& thePoint, const std::string& theAttribute); + + /// \brief Set the point to the line by the point of the source line. + /// \param theSourceFeature the feature, where the point is obtained + /// \param theSourceAttribute the start or end attribute of the source line + /// \param theAttribute the start or end attribute of the line + void setLinePoint(boost::shared_ptr theSourceFeature, + const std::string& theSourceAttribute, + const std::string& theAttribute); + /// \brief Converts the 3D point to the projected coodinates on the sketch plane. + /// \param thePoint the 3D point in the viewer + /// \param theX the X coordinate + /// \param theY the Y coordinate + void convertTo2D(const gp_Pnt& thePoint, double& theX, double& theY); + +protected: + ///< Structure to lists the possible types of point selection modes + enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint, SM_None}; + +private: + boost::shared_ptr mySketch; ///< the sketch feature + //PointSelectionMode myPointSelectionMode; ///< point selection mode +}; + +#endif diff --git a/src/PartSet/PartSet_OperationSketch.cpp b/src/PartSet/PartSet_OperationSketch.cpp index ee9334b32..6c274b66e 100644 --- a/src/PartSet/PartSet_OperationSketch.cpp +++ b/src/PartSet/PartSet_OperationSketch.cpp @@ -38,18 +38,22 @@ std::list PartSet_OperationSketch::getSelectionModes(boost::shared_ptr& theList) +void PartSet_OperationSketch::setSelected(boost::shared_ptr theFeature, + const TopoDS_Shape& theShape) { - if (theList.IsEmpty()) - return; - - if (isEditMode()) - return; + if (!isEditMode()) { + setSketchPlane(theShape); + setEditMode(true); + } + else if (theFeature) + emit launchOperation("EditLine", theFeature); +} +void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape) +{ // get selected shape - const TopoDS_Shape& aShape = theList.First(); boost::shared_ptr aGShape(new GeomAPI_Shape); - aGShape->setImpl(new TopoDS_Shape(aShape)); + aGShape->setImpl(new TopoDS_Shape(theShape)); // get plane parameters boost::shared_ptr aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape); @@ -79,10 +83,7 @@ void PartSet_OperationSketch::setSelectedShapes(const NCollection_List aDirY = boost::dynamic_pointer_cast(aData->attribute(SKETCH_ATTR_DIRY)); aDirY->setValue(aC, anA, aB); - boost::shared_ptr aDir = aPlane->direction(); emit planeSelected(aDir->x(), aDir->y(), aDir->z()); - - //commit(); - //SketchPlugin_Sketch::setActive(myFeature); } + diff --git a/src/PartSet/PartSet_OperationSketch.h b/src/PartSet/PartSet_OperationSketch.h index e577962bb..9250595c4 100644 --- a/src/PartSet/PartSet_OperationSketch.h +++ b/src/PartSet/PartSet_OperationSketch.h @@ -31,9 +31,10 @@ public: virtual std::list getSelectionModes(boost::shared_ptr theFeature) const; /// Gives the current selected objects to be processed by the operation - /// \param theList a list of interactive selected shapes - /// \param theSelectedPoint a point clidked in the viewer - virtual void setSelectedShapes(const NCollection_List& theList); + /// \param theFeature the selected feature + /// \param theShape the selected shape + virtual void setSelected(boost::shared_ptr theFeature, + const TopoDS_Shape& theShape); signals: /// signal about the sketch plane is selected @@ -41,6 +42,11 @@ signals: /// \param theX the value in the Y direction value of the plane /// \param theX the value in the Z direction of the plane void planeSelected(double theX, double theY, double theZ); + +protected: + /// Set the plane to the current sketch + /// \param theShape the shape + void setSketchPlane(const TopoDS_Shape& theShape); }; #endif diff --git a/src/PartSet/PartSet_OperationSketchBase.h b/src/PartSet/PartSet_OperationSketchBase.h index 173851cbc..7814bc935 100644 --- a/src/PartSet/PartSet_OperationSketchBase.h +++ b/src/PartSet/PartSet_OperationSketchBase.h @@ -45,9 +45,15 @@ public: /// \return the selection mode virtual std::list getSelectionModes(boost::shared_ptr theFeature) const = 0; + /// Initializes some fields accorging to the feature + /// \param theFeature the feature + virtual void init(boost::shared_ptr theFeature) {} + /// Gives the current selected objects to be processed by the operation - /// \param theList a list of interactive selected shapes - virtual void setSelectedShapes(const NCollection_List& theList) {}; + /// \param theFeature the selected feature + /// \param theShape the selected shape + virtual void setSelected(boost::shared_ptr theFeature, + const TopoDS_Shape& theShape) {}; /// Processes the mouse release in the point /// \param thePoint a point clicked in the viewer @@ -67,6 +73,10 @@ signals: /// \param theMode the mode of the feature modification void featureConstructed(boost::shared_ptr theFeature, int theMode); + /// signal about the request to launch operation + /// theName the operation name + /// theFeature the operation argument + void launchOperation(std::string theName, boost::shared_ptr theFeature); public: /// temporary code to provide edition mode diff --git a/src/PartSet/PartSet_OperationSketchLine.cpp b/src/PartSet/PartSet_OperationSketchLine.cpp index 14e0502b5..21f09e9c1 100644 --- a/src/PartSet/PartSet_OperationSketchLine.cpp +++ b/src/PartSet/PartSet_OperationSketchLine.cpp @@ -132,16 +132,17 @@ void PartSet_OperationSketchLine::stopOperation() myPointSelectionMode = SM_None; } -void PartSet_OperationSketchLine::createFeature() +boost::shared_ptr PartSet_OperationSketchLine::createFeature() { - PartSet_OperationSketchBase::createFeature(); + boost::shared_ptr aNewFeature = PartSet_OperationSketchBase::createFeature(); if (mySketch) { boost::shared_ptr aFeature = boost::dynamic_pointer_cast(mySketch); - aFeature->addSub(feature()); + aFeature->addSub(aNewFeature); } - //emit featureConstructed(aPrevFeature, FM_Activation); + //emit featureConstructed(aNewFeature, FM_Activation); + return aNewFeature; } void PartSet_OperationSketchLine::setLinePoint(const gp_Pnt& thePoint, diff --git a/src/PartSet/PartSet_OperationSketchLine.h b/src/PartSet/PartSet_OperationSketchLine.h index 7883143fa..604baffa3 100644 --- a/src/PartSet/PartSet_OperationSketchLine.h +++ b/src/PartSet/PartSet_OperationSketchLine.h @@ -65,9 +65,11 @@ protected: /// After the parent operation body perform, reset selection point mode of the operation virtual void stopOperation(); - /// Creates a new feature and save it in the operation internal field. - /// In addition to the default realization it set a sketch feature to the created feature - virtual void createFeature(); + /// Creates an operation new feature + /// In addition to the default realization it appends the created line feature to + /// the sketch feature + /// \returns the created feature + virtual boost::shared_ptr createFeature(); protected: /// \brief Save the point to the line. diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index c0a57d545..8e79d48fb 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -53,6 +53,30 @@ void XGUI_Displayer::Display(boost::shared_ptr theFeature, aContext->UpdateCurrentViewer(); } +boost::shared_ptr XGUI_Displayer::GetFeature(const TopoDS_Shape& theShape) +{ + boost::shared_ptr aFeature; + + FeatureToAISMap::const_iterator aFIt = myFeature2AISObjectMap.begin(), + aFLast = myFeature2AISObjectMap.end(); + for (; aFIt != aFLast && !aFeature; aFIt++) + { + std::vector aDispAIS = (*aFIt).second; + std::vector::const_iterator anIt = aDispAIS.begin(), + aLast = aDispAIS.end(); + Handle(AIS_InteractiveContext) aContext = AISContext(); + for (; anIt != aLast && !aFeature; anIt++) { + Handle(AIS_InteractiveObject) anAIS = *anIt; + Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS); + if (!anAISShape.IsNull() && anAISShape->Shape() == theShape) { + aFeature = (*aFIt).first; + } + } + } + + return aFeature; +} + void XGUI_Displayer::Erase(boost::shared_ptr theFeature, const bool isUpdateViewer) { diff --git a/src/XGUI/XGUI_Displayer.h b/src/XGUI/XGUI_Displayer.h index ec9d69649..a7f043d8e 100644 --- a/src/XGUI/XGUI_Displayer.h +++ b/src/XGUI/XGUI_Displayer.h @@ -55,6 +55,10 @@ public: void Display(boost::shared_ptr theFeature, const TopoDS_Shape& theShape, const bool isUpdateViewer = true); + /// Returns the feature, that was displayed with this shape + /// \param theShape a shape + boost::shared_ptr GetFeature( const TopoDS_Shape& theShape ); + /// Display the shape and activate selection of sub-shapes /// \param theFeature a feature instance /// \param theShape a shape @@ -83,7 +87,9 @@ protected: protected: XGUI_Workshop* myWorkshop; - std::map, std::vector > myFeature2AISObjectMap; + + typedef std::map, std::vector > FeatureToAISMap; + FeatureToAISMap myFeature2AISObjectMap; }; #endif diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index a956d0487..2c3969658 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -204,6 +204,7 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage) (ModuleBase_Operation*)(aPartSetMsg->pointer()); if (myOperationMgr->startOperation(anOperation)) { + myPropertyPanel->updateContentWidget(anOperation->feature()); if (anOperation->getDescription()->xmlRepresentation().isEmpty()) { anOperation->commit(); updateCommandStatus();