From: vsv Date: Wed, 19 Jun 2019 14:50:38 +0000 (+0300) Subject: Issue #2927: Show/Hide markers on free points X-Git-Tag: VEDF2019Lot4~105 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ca1ced8be909571c1943ddb2f32d475e9324e30f;p=modules%2Fshaper.git Issue #2927: Show/Hide markers on free points --- diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index f202db9f6..bbf82b6be 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -892,6 +892,8 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr&))); connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)), mySketchMgr, SLOT(onShowConstraintsToggle(int, bool))); + connect(aLabelWgt, SIGNAL(showFreePoints(bool)), mySketchMgr, SLOT(onShowPoints(bool))); + aLabelWgt->setShowPointsState(mySketchMgr->isShowFreePointsShown()); aWgt = aLabelWgt; } else if (theType == "sketch-2dpoint_selector") { PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop, diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index cca6529d8..40925340b 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -61,6 +61,8 @@ #include +#include + #include #include @@ -1065,6 +1067,7 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation) delete myExternalPointsMgr; myExternalPointsMgr = 0; } + onShowPoints(false); XGUI_ModuleConnector* aConnector = dynamic_cast(myModule->workshop()); @@ -1163,6 +1166,8 @@ void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation) } if (isClearSelectionPossible) workshop()->selector()->clearSelection(); + if (myPointsHighlight.size()) + onShowPoints(true); } void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation) @@ -1990,3 +1995,63 @@ XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const return workshop()->operationMgr(); } +void PartSet_SketcherMgr::onShowPoints(bool toShow) +{ + if (!myCurrentSketch.get()) + return; + ModuleBase_IWorkshop* aWorkshop = myModule->workshop(); + ModuleBase_IViewer* aViewer = aWorkshop->viewer(); + Handle(AIS_InteractiveContext) aContext = aViewer->AISContext(); + + bool aToUpdate = false; + if (toShow) { + std::list aFreePoints = SketcherPrs_Tools::getFreePoints(myCurrentSketch); + + // Delete obsolete presentations + std::list aDelList; + foreach(ResultPtr aObj, myPointsHighlight.keys()) { + bool aFound = (std::find(aFreePoints.begin(), aFreePoints.end(), aObj) != aFreePoints.end()); + if (!aFound) + aDelList.push_back(aObj); + } + foreach(ResultPtr aObj, aDelList) { + aContext->Remove(myPointsHighlight[aObj], false); + aToUpdate = true; + myPointsHighlight.remove(aObj); + } + + // Display new objects + QList aKeysList = myPointsHighlight.keys(); + std::list::const_iterator aIt; + for (aIt = aFreePoints.cbegin(); aIt != aFreePoints.cend(); aIt++) { + if (!aKeysList.contains(*aIt)) { + GeomShapePtr aShapePtr = (*aIt)->shape(); + TopoDS_Shape aShape = aShapePtr->impl(); + Handle(AIS_Shape) aShapePrs = new AIS_Shape(aShape); + aShapePrs->SetColor(Quantity_NOC_BLUE1); + aShapePrs->SetZLayer(Graphic3d_ZLayerId_Top); + Handle(Prs3d_Drawer) aDrawer = aShapePrs->Attributes(); + if (aDrawer->HasOwnPointAspect()) { + aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_O_STAR); + aDrawer->PointAspect()->SetColor(Quantity_NOC_BLUE1); + aDrawer->PointAspect()->SetScale(2); + } + else + aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_O_STAR, Quantity_NOC_BLUE1, 2)); + aContext->Display(aShapePrs, false); + aContext->Deactivate(aShapePrs); + myPointsHighlight[*aIt] = aShapePrs; + aToUpdate = true; + } + } + } + else { + foreach(Handle(AIS_Shape) aPrs, myPointsHighlight.values()) { + aContext->Remove(aPrs, false); + aToUpdate = true; + } + myPointsHighlight.clear(); + } + if (aToUpdate) + aViewer->update(); +} diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index 0be54180b..07c3160e6 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -335,10 +336,16 @@ public: void updateBySketchParameters(const PartSet_Tools::ConstraintVisibleState& theType, bool theState); + bool isShowFreePointsShown() const { + return myPointsHighlight.size() > 0; + } + public slots: /// Process sketch plane selected event void onPlaneSelected(const std::shared_ptr& thePln); + void onShowPoints(bool toShow); + private slots: /// Toggle show constraints void onShowConstraintsToggle(int theType, bool theState); @@ -452,6 +459,8 @@ private: QMap myIsConstraintsShown; PartSet_ExternalPointsMgr* myExternalPointsMgr; + + QMap myPointsHighlight; }; diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index aea6f47f1..75386d957 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -167,7 +167,9 @@ myIsSelection(false) if (toShowConstraints.contains(aState)) aShowConstraints->setChecked(toShowConstraints[aState]); } - + myShowPoints = new QCheckBox(tr("Show free points"), this); + connect(myShowPoints, SIGNAL(toggled(bool)), this, SIGNAL(showFreePoints(bool))); + aLayout->addWidget(myShowPoints); QPushButton* aPlaneBtn = new QPushButton(tr("Change sketch plane"), aSecondWgt); connect(aPlaneBtn, SIGNAL(clicked(bool)), SLOT(onChangePlane())); @@ -698,4 +700,11 @@ void PartSet_WidgetSketchLabel::onChangePlane() aMgr->startOperation(); myOpenTransaction = true; } -} \ No newline at end of file +} + +void PartSet_WidgetSketchLabel::setShowPointsState(bool theState) +{ + bool aBlock = myShowPoints->blockSignals(true); + myShowPoints->setChecked(theState); + myShowPoints->blockSignals(aBlock); +} diff --git a/src/PartSet/PartSet_WidgetSketchLabel.h b/src/PartSet/PartSet_WidgetSketchLabel.h index 4add82b00..74a16f224 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.h +++ b/src/PartSet/PartSet_WidgetSketchLabel.h @@ -101,6 +101,10 @@ public: virtual void setHighlighted(bool) { /*do nothing*/ }; virtual void enableFocusProcessing(); + /// Set current state of show free points + /// \param theState a state of the corresponded check box + void setShowPointsState(bool theState); + /// Returns True if the selected presentation can be used for plane definition /// \param thePrs a presentation static bool canFillSketch(const std::shared_ptr& thePrs); @@ -114,6 +118,8 @@ signals: /// \param theState a state of the check box void showConstraintToggled(int theType, bool theState); + void showFreePoints(bool toShow); + protected: /// Creates a backup of the current values of the attribute /// It should be realized in the specific widget because of different @@ -216,6 +222,7 @@ private: QCheckBox* myViewInverted; QCheckBox* myRemoveExternal; + QCheckBox* myShowPoints; QMap myShowConstraints;