From: vsv Date: Tue, 31 Mar 2015 16:05:03 +0000 (+0300) Subject: Create check box "Show constraints" X-Git-Tag: V_1.1.0~69 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=87aaa6244dbdd6e4fb6440d7516df672679f8701;p=modules%2Fshaper.git Create check box "Show constraints" --- diff --git a/src/ModuleBase/ModuleBase_IWorkshop.h b/src/ModuleBase/ModuleBase_IWorkshop.h index 3646e630c..87da9de58 100644 --- a/src/ModuleBase/ModuleBase_IWorkshop.h +++ b/src/ModuleBase/ModuleBase_IWorkshop.h @@ -19,6 +19,7 @@ class ModuleBase_IModule; class ModuleBase_ISelection; class ModuleBase_IViewer; +class ModuleBase_IPropertyPanel; class ModuleBase_Operation; class ModuleBase_FilterFactory; @@ -53,6 +54,9 @@ Q_OBJECT //! Returns current viewer virtual ModuleBase_IViewer* viewer() const = 0; + //! Returns property panel + virtual ModuleBase_IPropertyPanel* propertyPanel() const = 0; + /// A filter to process an attribute validators /// \return a filter Handle(ModuleBase_FilterValidated) validatorFilter(); diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 3603d3cd0..0fb009497 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -467,10 +467,13 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th XGUI_Workshop* aWorkshop = aConnector->workshop(); ModuleBase_ModelWidget* aWgt = NULL; if (theType == "sketch-start-label") { - PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, theWidgetApi, theParentId); + PartSet_WidgetSketchLabel* aLabelWgt = new PartSet_WidgetSketchLabel(theParent, + theWidgetApi, theParentId, mySketchMgr->isConstraintsShown()); aLabelWgt->setWorkshop(aWorkshop); connect(aLabelWgt, SIGNAL(planeSelected(const std::shared_ptr&)), mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr&))); + connect(aLabelWgt, SIGNAL(showConstraintToggled(bool)), + mySketchMgr, SLOT(onShowConstraintsToggle(bool))); aWgt = aLabelWgt; } else if (theType == "sketch-2dpoint_selector") { PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, theWidgetApi, theParentId); @@ -672,7 +675,7 @@ void PartSet_Module::onViewTransformed(int theTrsfType) XGUI_Displayer* aDisplayer = aWorkshop->displayer(); Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); - double aLen = aView->Convert(25); + double aLen = aView->Convert(15); SketcherPrs_Tools::setArrowSize(aLen); bool isModified = false; diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 6a8c084db..10a008fee 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -9,6 +9,7 @@ #include "PartSet_WidgetPoint2d.h" #include "PartSet_WidgetPoint2dDistance.h" #include "PartSet_Tools.h" +#include "PartSet_WidgetSketchLabel.h" #include @@ -53,6 +54,8 @@ #include #include #include +#include +#include #include #include @@ -122,7 +125,7 @@ PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule) : QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false), myIsPropertyPanelValueChanged(false), myIsMouseOverWindow(false), myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true), - myIsPopupMenuActive(false) + myIsPopupMenuActive(false), myIsConstraintsShown(true) { ModuleBase_IWorkshop* anIWorkshop = myModule->workshop(); ModuleBase_IViewer* aViewer = anIWorkshop->viewer(); @@ -572,7 +575,7 @@ void PartSet_SketcherMgr::launchEditing() } -QStringList PartSet_SketcherMgr::sketchOperationIdList() +const QStringList& PartSet_SketcherMgr::sketchOperationIdList() { static QStringList aIds; if (aIds.size() == 0) { @@ -591,10 +594,33 @@ QStringList PartSet_SketcherMgr::sketchOperationIdList() aIds << SketchPlugin_ConstraintEqual::ID().c_str(); aIds << SketchPlugin_ConstraintTangent::ID().c_str(); aIds << SketchPlugin_ConstraintCoincidence::ID().c_str(); + aIds << SketchPlugin_ConstraintFillet::ID().c_str(); + aIds << SketchPlugin_ConstraintMirror::ID().c_str(); } return aIds; } +const QStringList& PartSet_SketcherMgr::constraintsIdList() +{ + static QStringList aIds; + if (aIds.size() == 0) { + aIds << SketchPlugin_ConstraintLength::ID().c_str(); + aIds << SketchPlugin_ConstraintDistance::ID().c_str(); + aIds << SketchPlugin_ConstraintRigid::ID().c_str(); + aIds << SketchPlugin_ConstraintRadius::ID().c_str(); + aIds << SketchPlugin_ConstraintPerpendicular::ID().c_str(); + aIds << SketchPlugin_ConstraintParallel::ID().c_str(); + aIds << SketchPlugin_ConstraintHorizontal::ID().c_str(); + aIds << SketchPlugin_ConstraintVertical::ID().c_str(); + aIds << SketchPlugin_ConstraintEqual::ID().c_str(); + aIds << SketchPlugin_ConstraintTangent::ID().c_str(); + aIds << SketchPlugin_ConstraintCoincidence::ID().c_str(); + aIds << SketchPlugin_ConstraintMirror::ID().c_str(); + } + return aIds; +} + + bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation) { return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID(); @@ -719,7 +745,7 @@ void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* ) connectToPropertyPanel(true); } -void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation) +void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp) { connectToPropertyPanel(false); myIsPropertyPanelValueChanged = false; @@ -730,6 +756,11 @@ void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation) { if (isNestedCreateOperation(theOperation)) visualizeFeature(theOperation, true); + + if (constraintsIdList().contains(theOperation->id())) { + // Show constraints if a constraint was created + onShowConstraintsToggle(true); + } } bool PartSet_SketcherMgr::canUndo() const @@ -1127,3 +1158,29 @@ void PartSet_SketcherMgr::restoreSelection() aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false); } } + +void PartSet_SketcherMgr::onShowConstraintsToggle(bool theOn) +{ + if (myIsConstraintsShown == theOn) + return; + if (myCurrentSketch.get() == NULL) + return; + + myIsConstraintsShown = theOn; + + ModuleBase_IWorkshop* aWorkshop = myModule->workshop(); + XGUI_ModuleConnector* aConnector = dynamic_cast(aWorkshop); + XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); + + const QStringList& aConstrIds = constraintsIdList(); + for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) { + FeaturePtr aSubFeature = myCurrentSketch->subFeature(i); + if (aConstrIds.contains(QString(aSubFeature->getKind().c_str()))) { + if (myIsConstraintsShown) + aDisplayer->display(aSubFeature, false); + else + aDisplayer->erase(aSubFeature, false); + } + } + aDisplayer->updateViewer(); +} diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index dc68f283a..aad09ef0f 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -146,6 +146,16 @@ public: /// \param isChecked if true, the feature is a construction void setAuxiliary(const bool isChecked); + + bool isConstraintsShown() const { return myIsConstraintsShown; } + + + /// Returns list of strings which contains id's of sketch operations + static const QStringList& sketchOperationIdList(); + + /// Returns list of strings which contains id's of constraints operations + static const QStringList& constraintsIdList(); + public slots: /// Process sketch plane selected event void onPlaneSelected(const std::shared_ptr& thePln); @@ -174,13 +184,12 @@ private slots: void onBeforeContextMenu(); void onAfterContextMenu(); + void onShowConstraintsToggle(bool); + private: /// Launches the operation from current highlighting void launchEditing(); - /// Returns list of strings which contains id's of sketch operations - static QStringList sketchOperationIdList(); - /// Converts mouse position to 2d coordinates. /// Member myCurrentSketch has to be correctly defined void get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent, @@ -263,6 +272,8 @@ private: Handle(ModuleBase_ShapeInPlaneFilter) myPlaneFilter; FeatureToSelectionMap myCurrentSelection; bool myPreviousUpdateViewerEnabled; + + bool myIsConstraintsShown; }; diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index e70a8a097..1b645c062 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -42,11 +42,13 @@ #include #include #include +#include PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent, const Config_WidgetAPI* theData, - const std::string& theParentId) + const std::string& theParentId, + bool toShowConstraints) : ModuleBase_WidgetValidated(theParent, theData, theParentId), myPreviewDisplayed(false), myWorkshop(NULL) @@ -65,7 +67,13 @@ PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent, QVBoxLayout* aLayout = new QVBoxLayout(this); ModuleBase_Tools::zeroMargins(aLayout); aLayout->addWidget(myLabel); + + myShowConstraints = new QCheckBox(tr("Show constraints"), this); + aLayout->addWidget(myShowConstraints); + setLayout(aLayout); + connect(myShowConstraints, SIGNAL(toggled(bool)), this, SIGNAL(showConstraintToggled(bool))); + myShowConstraints->setChecked(toShowConstraints); } PartSet_WidgetSketchLabel::~PartSet_WidgetSketchLabel() @@ -359,3 +367,9 @@ void PartSet_WidgetSketchLabel::setSketchingMode() aDisp->activateObjects(aModes); } + +void PartSet_WidgetSketchLabel::showConstraints(bool theOn) +{ + myShowConstraints->setChecked(theOn); + emit showConstraintToggled(theOn); +} diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index a0a069f78..0b26103a4 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -22,6 +22,7 @@ class QLabel; class QTimer; class XGUI_OperationMgr; class XGUI_Workshop; +class QCheckBox; /// the plane edge width #define SKETCH_WIDTH "4" @@ -43,7 +44,7 @@ Q_OBJECT /// \param theData the widget configuation. The attribute of the model widget is obtained from /// \param theParentId is Id of a parent of the current attribute PartSet_WidgetSketchLabel(QWidget* theParent, const Config_WidgetAPI* theData, - const std::string& theParentId); + const std::string& theParentId, bool toShowConstraints); virtual ~PartSet_WidgetSketchLabel(); @@ -74,10 +75,14 @@ Q_OBJECT virtual void setHighlighted(bool) { /*do nothing*/ }; virtual void enableFocusProcessing(); + void showConstraints(bool theOn); + signals: /// Signal on plane selection void planeSelected(const std::shared_ptr& thePln); + void showConstraintToggled(bool); + protected: /// Creates a backup of the current values of the attribute /// It should be realized in the specific widget because of different @@ -143,6 +148,8 @@ protected: bool myPreviewDisplayed; QTimer* mySelectionTimer; + + QCheckBox* myShowConstraints; }; #endif diff --git a/src/SketcherPrs/SketcherPrs_LengthDimension.cpp b/src/SketcherPrs/SketcherPrs_LengthDimension.cpp index f3220e6b6..65b067782 100644 --- a/src/SketcherPrs/SketcherPrs_LengthDimension.cpp +++ b/src/SketcherPrs/SketcherPrs_LengthDimension.cpp @@ -27,8 +27,6 @@ static const gp_Pnt MyDefStart(0,0,0); static const gp_Pnt MyDefEnd(1,0,0); static const gp_Pln MyDefPln(gp_Pnt(0,0,0), gp_Dir(0,0,1)); -static const double MyTextHeight = 20; - IMPLEMENT_STANDARD_HANDLE(SketcherPrs_LengthDimension, AIS_LengthDimension); IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_LengthDimension, AIS_LengthDimension); diff --git a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp index e7648db53..1e8a9ee7d 100644 --- a/src/SketcherPrs/SketcherPrs_PositionMgr.cpp +++ b/src/SketcherPrs/SketcherPrs_PositionMgr.cpp @@ -28,27 +28,27 @@ SketcherPrs_PositionMgr::SketcherPrs_PositionMgr() int SketcherPrs_PositionMgr::getPositionIndex(ObjectPtr theLine, - Handle(SketcherPrs_SymbolPrs) thePrs) + const SketcherPrs_SymbolPrs* thePrs) { if (myShapes.count(theLine) == 1) { PositionsMap& aPosMap = myShapes[theLine]; - if (aPosMap.count(thePrs.Access()) == 1) { - return aPosMap[thePrs.Access()]; + if (aPosMap.count(thePrs) == 1) { + return aPosMap[thePrs]; } else { int aInd = aPosMap.size(); - aPosMap[thePrs.Access()] = aInd; + aPosMap[thePrs] = aInd; return aInd; } } else { PositionsMap aPosMap; - aPosMap[thePrs.Access()] = 0; + aPosMap[thePrs] = 0; myShapes[theLine] = aPosMap; return 0; } } gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape, - Handle(SketcherPrs_SymbolPrs) thePrs, + const SketcherPrs_SymbolPrs* thePrs, double theStep) { std::shared_ptr aShape = SketcherPrs_Tools::getShape(theShape); @@ -122,18 +122,20 @@ gp_Pnt SketcherPrs_PositionMgr::getPosition(ObjectPtr theShape, return aP; } -void SketcherPrs_PositionMgr::deleteConstraint(Handle(SketcherPrs_SymbolPrs) thePrs) +void SketcherPrs_PositionMgr::deleteConstraint(const SketcherPrs_SymbolPrs* thePrs) { std::map::iterator aIt; + std::list aToDel; for (aIt = myShapes.begin(); aIt != myShapes.end(); ++aIt) { PositionsMap& aPosMap = aIt->second; - if (aPosMap.count(thePrs.Access()) > 0) - aPosMap.erase(aPosMap.find(thePrs.Access())); - } - for (aIt = myShapes.begin(); aIt != myShapes.end(); ++aIt) { - if (aIt->second.size() == 0) { - myShapes.erase(aIt); - aIt = myShapes.begin(); + if (aPosMap.count(thePrs) > 0) { + aPosMap.erase(aPosMap.find(thePrs)); + if (aPosMap.size() == 0) + aToDel.push_back(aIt->first); } } + std::list::const_iterator aListIt; + for (aListIt = aToDel.cbegin(); aListIt != aToDel.cend(); ++aListIt) { + myShapes.erase(*aListIt); + } } diff --git a/src/SketcherPrs/SketcherPrs_PositionMgr.h b/src/SketcherPrs/SketcherPrs_PositionMgr.h index fd61fa64f..d8a956ff9 100644 --- a/src/SketcherPrs/SketcherPrs_PositionMgr.h +++ b/src/SketcherPrs/SketcherPrs_PositionMgr.h @@ -30,11 +30,11 @@ public: /// \param theLine constrained object /// \param thePrs a presentation of constraint /// \param theStep step between symbols - gp_Pnt getPosition(ObjectPtr theLine, Handle(SketcherPrs_SymbolPrs) thePrs, double theStep = 20); + gp_Pnt getPosition(ObjectPtr theLine, const SketcherPrs_SymbolPrs* thePrs, double theStep = 20); /// Deletes constraint object from internal structures. Has to be called on constraint delete. /// \param thePrs a constraint presentation - void deleteConstraint(Handle(SketcherPrs_SymbolPrs) thePrs); + void deleteConstraint(const SketcherPrs_SymbolPrs* thePrs); private: /// Constructor @@ -43,10 +43,10 @@ private: /// Returns position index of the given constraint /// \param theLine constrained object /// \param thePrs a presentation of constraint - int getPositionIndex(ObjectPtr theLine, Handle(SketcherPrs_SymbolPrs) thePrs); + int getPositionIndex(ObjectPtr theLine, const SketcherPrs_SymbolPrs* thePrs); private: - typedef std::map PositionsMap; + typedef std::map PositionsMap; /// The map which contains position of presentation PositionsMap myIndexes; diff --git a/src/SketcherPrs/SketcherPrs_Radius.cpp b/src/SketcherPrs/SketcherPrs_Radius.cpp index bb517cc80..07957c4db 100644 --- a/src/SketcherPrs/SketcherPrs_Radius.cpp +++ b/src/SketcherPrs/SketcherPrs_Radius.cpp @@ -19,7 +19,6 @@ #include static const gp_Circ MyDefCirc(gp_Ax2(gp_Pnt(0,0,0), gp_Dir(0,0,1)), 1); -static const double MyTextHeight = 20; IMPLEMENT_STANDARD_HANDLE(SketcherPrs_Radius, AIS_RadiusDimension); IMPLEMENT_STANDARD_RTTIEXT(SketcherPrs_Radius, AIS_RadiusDimension); diff --git a/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp b/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp index b502c47e9..a74dfc82a 100644 --- a/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp +++ b/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp @@ -6,6 +6,7 @@ #include "SketcherPrs_SymbolPrs.h" #include "SketcherPrs_Tools.h" +#include "SketcherPrs_PositionMgr.h" #include @@ -225,6 +226,13 @@ SketcherPrs_SymbolPrs::SketcherPrs_SymbolPrs(SketchPlugin_Constraint* theConstra SetAutoHilight(Standard_False); } +SketcherPrs_SymbolPrs::~SketcherPrs_SymbolPrs() +{ + SketcherPrs_PositionMgr* aMgr = SketcherPrs_PositionMgr::get(); + aMgr->deleteConstraint(this); +} + + Handle(Image_AlienPixMap) SketcherPrs_SymbolPrs::icon() { diff --git a/src/SketcherPrs/SketcherPrs_SymbolPrs.h b/src/SketcherPrs/SketcherPrs_SymbolPrs.h index c087ff6ba..9145705f5 100644 --- a/src/SketcherPrs/SketcherPrs_SymbolPrs.h +++ b/src/SketcherPrs/SketcherPrs_SymbolPrs.h @@ -41,6 +41,8 @@ public: Standard_EXPORT SketcherPrs_SymbolPrs(SketchPlugin_Constraint* theConstraint, const std::shared_ptr& thePlane); + virtual ~SketcherPrs_SymbolPrs(); + //! Method which clear all selected owners belonging //! to this selectable object ( for fast presentation draw ) Standard_EXPORT virtual void ClearSelected(); diff --git a/src/SketcherPrs/SketcherPrs_Tools.cpp b/src/SketcherPrs/SketcherPrs_Tools.cpp index e2973e9f9..c94864db6 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.cpp +++ b/src/SketcherPrs/SketcherPrs_Tools.cpp @@ -134,7 +134,7 @@ std::shared_ptr getProjectionPoint( } -static double MyArrowSize = 40.; +static double MyArrowSize = 30.; double getArrowSize() { return MyArrowSize; diff --git a/src/SketcherPrs/SketcherPrs_Tools.h b/src/SketcherPrs/SketcherPrs_Tools.h index da29b72bd..294465963 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.h +++ b/src/SketcherPrs/SketcherPrs_Tools.h @@ -17,6 +17,8 @@ class SketchPlugin_Constraint; class SketchPlugin_Line; class GeomDataAPI_Point2D; +#define MyTextHeight 20 + namespace SketcherPrs_Tools { SKETCHERPRS_EXPORT ObjectPtr getResult(SketchPlugin_Constraint* theFeature, diff --git a/src/XGUI/XGUI_ModuleConnector.cpp b/src/XGUI/XGUI_ModuleConnector.cpp index c53bc38f4..ab9991d50 100644 --- a/src/XGUI/XGUI_ModuleConnector.cpp +++ b/src/XGUI/XGUI_ModuleConnector.cpp @@ -11,6 +11,7 @@ #include "XGUI_Selection.h" #include "XGUI_OperationMgr.h" #include "XGUI_Displayer.h" +#include "XGUI_PropertyPanel.h" #include @@ -47,6 +48,11 @@ ModuleBase_IViewer* XGUI_ModuleConnector::viewer() const return myWorkshop->viewer(); } +ModuleBase_IPropertyPanel* XGUI_ModuleConnector::propertyPanel() const +{ + return myWorkshop->propertyPanel(); +} + ModuleBase_Operation* XGUI_ModuleConnector::currentOperation() const { return myWorkshop->operationMgr()->currentOperation(); @@ -102,3 +108,4 @@ bool XGUI_ModuleConnector::canStartOperation(QString theId) { return myWorkshop->operationMgr()->canStartOperation(theId); } + diff --git a/src/XGUI/XGUI_ModuleConnector.h b/src/XGUI/XGUI_ModuleConnector.h index 266967988..e78228378 100644 --- a/src/XGUI/XGUI_ModuleConnector.h +++ b/src/XGUI/XGUI_ModuleConnector.h @@ -46,6 +46,9 @@ Q_OBJECT //! Returns current viewer virtual ModuleBase_IViewer* viewer() const; + //! Returns property panel + virtual ModuleBase_IPropertyPanel* propertyPanel() const; + //! Returns currently active operation virtual ModuleBase_Operation* currentOperation() const;