From 9ddba1caf0817c1e95c55d4c5b8ae6de23cbe6d5 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 3 Jul 2015 08:47:16 +0300 Subject: [PATCH] Issue #591 - Highlight of the first argument of constraints --- src/GeomAPI/GeomAPI_AISObject.cpp | 2 - src/ModuleBase/ModuleBase_Operation.cpp | 15 ++ src/ModuleBase/ModuleBase_Operation.h | 6 + src/PartSet/PartSet_CustomPrs.cpp | 188 +++++++----------- src/PartSet/PartSet_CustomPrs.h | 31 ++- src/PartSet/PartSet_Module.cpp | 42 ++-- src/PartSet/PartSet_Module.h | 4 + src/PartSet/PartSet_OperationPrs.cpp | 207 +++++++++++++------- src/PartSet/PartSet_OperationPrs.h | 50 ++++- src/PartSet/PartSet_SketcherMgr.cpp | 9 - src/PartSet/PartSet_Tools.cpp | 69 +++++++ src/PartSet/PartSet_Tools.h | 12 +- src/PartSet/PartSet_WidgetShapeSelector.cpp | 54 +---- src/XGUI/XGUI_Displayer.cpp | 8 +- 14 files changed, 411 insertions(+), 286 deletions(-) diff --git a/src/GeomAPI/GeomAPI_AISObject.cpp b/src/GeomAPI/GeomAPI_AISObject.cpp index 236574665..fc34c50ae 100644 --- a/src/GeomAPI/GeomAPI_AISObject.cpp +++ b/src/GeomAPI/GeomAPI_AISObject.cpp @@ -272,7 +272,6 @@ void GeomAPI_AISObject::setColor(const int& theColor) if (anAIS.IsNull()) return; Quantity_Color aColor((Quantity_NameOfColor) theColor); - anAIS->SetColor(aColor); Handle(AIS_Dimension) aDimAIS = Handle(AIS_Dimension)::DownCast(anAIS); if (!aDimAIS.IsNull()) { aDimAIS->DimensionAspect()->SetCommonColor(aColor); @@ -305,7 +304,6 @@ bool GeomAPI_AISObject::setColor(int theR, int theG, int theB) if (aColor.IsEqual(aCurrentColor)) return false; - anAIS->SetColor(aColor); Handle(AIS_Dimension) aDimAIS = Handle(AIS_Dimension)::DownCast(anAIS); if (!aDimAIS.IsNull()) { aDimAIS->DimensionAspect()->SetCommonColor(aColor); diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 7484ff28d..58891e564 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -136,6 +136,7 @@ bool ModuleBase_Operation::hasObject(ObjectPtr theObj) const void ModuleBase_Operation::start() { + myIsModified = false; QString anId = getDescription()->operationId(); if (myIsEditing) { anId = anId.append(EditSuffix()); @@ -255,6 +256,11 @@ void ModuleBase_Operation::setRunning(bool theState) emit triggered(theState); } +void ModuleBase_Operation::onValuesChanged() +{ + myIsModified = true; +} + //TODO: nds stabilization hotfix void ModuleBase_Operation::commitOperation() { @@ -375,6 +381,15 @@ void ModuleBase_Operation::setPropertyPanel(ModuleBase_IPropertyPanel* theProp) myPropertyPanel = theProp; myPropertyPanel->setEditingMode(isEditOperation()); + if (myPropertyPanel) { + const QList& aWidgets = myPropertyPanel->modelWidgets(); + QList::const_iterator aWIt; + for (aWIt = aWidgets.constBegin(); aWIt != aWidgets.constEnd(); ++aWIt) { + ModuleBase_ModelWidget* aWgt = (*aWIt); + connect(aWgt, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged())); + } + } + // Do not activate widgets by default if the current operation is editing operation // Because we don't know which widget is going to be edited. if (!isEditOperation()) diff --git a/src/ModuleBase/ModuleBase_Operation.h b/src/ModuleBase/ModuleBase_Operation.h index c20391185..9d304e715 100644 --- a/src/ModuleBase/ModuleBase_Operation.h +++ b/src/ModuleBase/ModuleBase_Operation.h @@ -76,6 +76,9 @@ Q_OBJECT /// Returns True if data of its feature was modified during operation virtual bool isModified() const { return myIsModified; } + /// Change the modified state of the operation + void setIsModified(const bool theIsModified) { myIsModified = theIsModified; } + /// Returns True id the current operation is launched in editing mode bool isEditOperation() const { return myIsEditing; } @@ -191,6 +194,9 @@ signals: /// \param theState th flag to abort, if it is true, do nothing, overwise abort void setRunning(bool theState); + /// Changes the modified flag of the operation + void onValuesChanged(); + protected: /// Virtual method called when operation started (see start() method for more description) /// Default impl calls corresponding slot and commits immediately. diff --git a/src/PartSet/PartSet_CustomPrs.cpp b/src/PartSet/PartSet_CustomPrs.cpp index 2990969e9..a90b634ac 100755 --- a/src/PartSet/PartSet_CustomPrs.cpp +++ b/src/PartSet/PartSet_CustomPrs.cpp @@ -5,6 +5,8 @@ // Author: Natalia ERMOLAEVA #include +#include +#include "PartSet_OperationPrs.h" #include #include @@ -21,139 +23,101 @@ #include #include +#include +#include #define OPERATION_PARAMETER_COLOR "255, 255, 0" PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop) : myWorkshop(theWorkshop) { - Handle(PartSet_OperationPrs) myOperationPrs = new PartSet_OperationPrs(); /// AIS presentation for the feature of operation + myOperationPrs = AISObjectPtr(new GeomAPI_AISObject()); + myOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(new PartSet_OperationPrs(theWorkshop))); + + std::vector aColor = Config_PropManager::color("Visualization", "operation_parameter_color", + OPERATION_PARAMETER_COLOR); + myOperationPrs->setColor(aColor[0], aColor[1], aColor[2]); + + myOperationPrs->setPointMarker(5, 2.); + myOperationPrs->setWidth(1); } -void PartSet_CustomPrs::setCustomized(const FeaturePtr& theFeature) +bool PartSet_CustomPrs::isActive() const { + Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); + Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + + return aContext->IsDisplayed(anOperationPrs); +} - myOperationPrs->setFeature(theFeature); - /* QMap > aNewCustomized; +void PartSet_CustomPrs::activate(const FeaturePtr& theFeature) +{ + Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); - QList aShapeList; - ResultPtr aResult = std::dynamic_pointer_cast(theObject); - if (aResult.get()) { - aNewCustomized[aResult] = aShapeList; - } - else { - FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); - if (aFeature.get()) { - std::list anAttributes = aFeature->data()->attributes(""); - std::list::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end(); - for (; anIt != aLast; anIt++) { - AttributePtr anAttribute = *anIt; - ObjectPtr anObject = GeomValidators_Tools::getObject(anAttribute); - if (anObject.get()) { - ResultPtr aResult = std::dynamic_pointer_cast(anObject); - if (aResult.get()) - aNewCustomized[aResult] = aShapeList; - } - else if (anAttribute->attributeType() == ModelAPI_AttributeSelectionList::typeId()) { - std::shared_ptr aCurSelList = - std::dynamic_pointer_cast(anAttribute); - for(int i = 0; i < aCurSelList->size(); i++) { - std::shared_ptr aSelAttribute = aCurSelList->value(i); - ObjectPtr anObject = GeomValidators_Tools::getObject(aSelAttribute); - if (anObject.get()) { - ResultPtr aResult = std::dynamic_pointer_cast(anObject); - if (aResult.get()) - aNewCustomized[aResult] = aShapeList; - } - } - } - } - } + if (anOperationPrs->canActivate(theFeature)) { + anOperationPrs->setFeature(theFeature); + if (theFeature.get()) + displayPresentation(); } +} + +void PartSet_CustomPrs::deactivate() +{ + Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); + anOperationPrs->setFeature(FeaturePtr()); + + erasePresentation(); +} + + +void PartSet_CustomPrs::displayPresentation() +{ + Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); - bool isDone = false; - XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); - XGUI_Workshop* aWorkshop = aConnector->workshop(); - XGUI_Displayer* aDisplayer = aWorkshop->displayer(); Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); - // find objects which are not customized anymore - QMap > aNotCustomized; - QMap >::const_iterator anIt = myCustomized.begin(), - aLast = myCustomized.end(); - for (; anIt != aLast; anIt++) { - ResultPtr aResult = anIt.key(); - if (!aNewCustomized.contains(aResult)) - aNotCustomized[aResult] = aShapeList; + if (!aContext->IsDisplayed(anOperationPrs)) { + PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); + aContext->Display(anOperationPrs); + aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId()); } + else + anOperationPrs->Redisplay(); +} - myCustomized.clear(); - // restore the previous state of the object if there is no such object in the new map - for (anIt = aNotCustomized.begin(), aLast = aNotCustomized.end(); anIt != aLast; anIt++) { - ResultPtr aResult = anIt.key(); - AISObjectPtr anAISObj = aDisplayer->getAISObject(aResult); - if (anAISObj.get()) { - Handle(AIS_InteractiveObject) anAISIO = anAISObj->impl(); - aContext->Redisplay(anAISIO, false); - } - isDone = aDisplayer->customizeObject(aResult); - } +void PartSet_CustomPrs::erasePresentation() +{ + Handle(AIS_InteractiveObject) anOperationPrs = myOperationPrs->impl(); + Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + if (aContext->IsDisplayed(anOperationPrs)) + aContext->Remove(anOperationPrs); +} + +Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation() const +{ + Handle(AIS_InteractiveObject) anAISIO = myOperationPrs->impl(); + return Handle(PartSet_OperationPrs)::DownCast(anAISIO); +} + +bool PartSet_CustomPrs::customize(const ObjectPtr& theObject) +{ + // the presentation should be recomputed if the previous AIS depend on the result + // [it should be hiddend] or the new AIS depend on it [it should be visualized] + Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(); + Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext(); + if (aContext->IsDisplayed(anOperationPrs)) { + bool aChanged = anOperationPrs->dependOn(theObject); - // set customized for the new objects - myCustomized = aNewCustomized; - for (anIt = myCustomized.begin(), aLast = myCustomized.end(); anIt != aLast; anIt++) { - ResultPtr aResult = anIt.key(); - AISObjectPtr anAISObj = aDisplayer->getAISObject(aResult); - if (anAISObj.get()) - isDone = customisePresentation(aResult, anAISObj, 0) || isDone; + anOperationPrs->updateShapes(); + aChanged = aChanged || anOperationPrs->dependOn(theObject); + + //if (aChanged) + anOperationPrs->Redisplay(); } - if (isDone) - aDisplayer->updateViewer();*/ + return false; } -/*#include -#include -#include -#include -#include -#include */ bool PartSet_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, std::shared_ptr theCustomPrs) { - bool isDone = false; - /*if (myCustomized.contains(theResult)) { - std::vector aColor = Config_PropManager::color("Visualization", "operation_parameter_color", - OPERATION_PARAMETER_COLOR); - isDone = thePrs->setColor(aColor[0], aColor[1], aColor[2]); - /* - Handle(AIS_InteractiveObject) anAISIO = thePrs->impl(); - - const Handle(Prs3d_Presentation)& aPresentation = anAISIO->Presentation(); - if (!aPresentation.IsNull()) { - Handle(AIS_Shape) aShapeAIS = Handle(AIS_Shape)::DownCast(anAISIO); - if (!aShapeAIS.IsNull()) { - TopExp_Explorer anExp(aShapeAIS->Shape(), TopAbs_VERTEX); - Handle(Prs3d_Drawer) aDrawer = aShapeAIS->Attributes(); - for (; anExp.More(); anExp.Next()) { - const TopoDS_Vertex& aVertex = (const TopoDS_Vertex&)anExp.Current(); - StdPrs_WFDeflectionShape::Add(aPresentation, aVertex, aDrawer); - } - } - } - thePrs->setPointMarker(5, 5.); // Set point as a '+' symbol*+/ - } - /* - std::vector aColor; - - getResultColor(theResult, aColor); - - SessionPtr aMgr = ModelAPI_Session::get(); - if (aMgr->activeDocument() != theResult->document()) { - QColor aQColor(aColor[0], aColor[1], aColor[2]); - QColor aNewColor = QColor::fromHsvF(aQColor.hueF(), aQColor.saturationF()/3., aQColor.valueF()); - aColor[0] = aNewColor.red(); - aColor[1] = aNewColor.green(); - aColor[2] = aNewColor.blue(); - } - return !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);*/ - return isDone; + return false; } diff --git a/src/PartSet/PartSet_CustomPrs.h b/src/PartSet/PartSet_CustomPrs.h index 6d23847da..6a34fbb2a 100755 --- a/src/PartSet/PartSet_CustomPrs.h +++ b/src/PartSet/PartSet_CustomPrs.h @@ -8,6 +8,7 @@ #define PartSet_CustomPrs_H #include "PartSet.h" + #include "PartSet_OperationPrs.h" #include @@ -18,9 +19,6 @@ #include #include -#include -#include - class ModuleBase_IWorkshop; /** @@ -33,17 +31,34 @@ public: PARTSET_EXPORT PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop); PARTSET_EXPORT virtual ~PartSet_CustomPrs() {}; - /// Set the feature is customized - /// \param theObject a feature object - void setCustomized(const FeaturePtr& theObject); + /// Returns true if the presentation is active + bool isActive() const; + + /// Initializes the presentation by the parameter object + void activate(const FeaturePtr& theObject); + + void deactivate(); + + /// Modifies the given presentation in the custom way. + bool customize(const ObjectPtr& theObject); /// Modifies the given presentation in the custom way. virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, std::shared_ptr theCustomPrs); +private: + /// Returns the AIS presentation + Handle(PartSet_OperationPrs) getPresentation() const; + + /// Displays the internal presentation in the viewer of workshop + void displayPresentation(); + /// Erases the internal presentation from the viewer of workshop + void erasePresentation(); + /// Sets color, point size and width of the presentation + void customizePresentation(); + private: ModuleBase_IWorkshop* myWorkshop; /// current workshop - Handle(PartSet_OperationPrs) myOperationPrs; /// AIS presentation for the feature of operation - //QMap > myCustomized; /// objects, which are customized + AISObjectPtr myOperationPrs; /// the AIS presentation, which is displayed/erased in the viewer }; #endif diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index cc9afc0d8..e997f05cf 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -267,27 +267,37 @@ void PartSet_Module::onOperationAborted(ModuleBase_Operation* theOperation) void PartSet_Module::onOperationStarted(ModuleBase_Operation* theOperation) { + // z layer is created for all started operations in order to visualize operation AIS presentation + // over the object + Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer(); + aViewer->AddZLayer(myVisualLayerId); + if (PartSet_SketcherMgr::isSketchOperation(theOperation)) { - Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer(); - aViewer->AddZLayer(myVisualLayerId); mySketchMgr->startSketch(theOperation); } else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) { mySketchMgr->startNestedSketch(theOperation); } + + std::shared_ptr aCustomPrs = + std::dynamic_pointer_cast(myCustomPrs); + aCustomPrs->activate(theOperation->feature()); } void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation) { if (PartSet_SketcherMgr::isSketchOperation(theOperation)) { mySketchMgr->stopSketch(theOperation); - Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer(); - aViewer->RemoveZLayer(myVisualLayerId); - myVisualLayerId = 0; } else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) { mySketchMgr->stopNestedSketch(theOperation); } + Handle(V3d_Viewer) aViewer = myWorkshop->viewer()->AISContext()->CurrentViewer(); + aViewer->RemoveZLayer(myVisualLayerId); + myVisualLayerId = 0; + std::shared_ptr aCustomPrs = + std::dynamic_pointer_cast(myCustomPrs); + aCustomPrs->deactivate(); } ModuleBase_Operation* PartSet_Module::currentOperation() const @@ -720,24 +730,14 @@ void PartSet_Module::onViewTransformed(int theTrsfType) aDisplayer->updateViewer(); } -void PartSet_Module::setCustomized(const FeaturePtr& theFeature) -{ - std::shared_ptr aCustomPrs = - std::dynamic_pointer_cast(myCustomPrs); - if (aCustomPrs.get()) - aCustomPrs->setCustomized(theFeature); -} - bool PartSet_Module::customizeObject(ObjectPtr theObject) { - ResultPtr aResult = std::dynamic_pointer_cast(theObject); - - XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); - XGUI_Workshop* aWorkshop = aConnector->workshop(); - XGUI_Displayer* aDisplayer = aWorkshop->displayer(); - - AISObjectPtr anAISObj = aDisplayer->getAISObject(aResult); - return myCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs); + std::shared_ptr aCustomPrs = + std::dynamic_pointer_cast(myCustomPrs); + bool isCustomized = false; + if (aCustomPrs->isActive()) + isCustomized = aCustomPrs->customize(theObject); + return isCustomized; } void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser) diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index ee0595b13..f946512a5 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -31,6 +31,7 @@ class ModuleBase_Operation; class ModuleBase_IViewWindow; class PartSet_MenuMgr; +class PartSet_CustomPrs; class PartSet_SketcherMgr; class QAction; @@ -160,6 +161,9 @@ public: /// \param theObjectBrowser a pinter on Object Browser widget virtual void customizeObjectBrowser(QWidget* theObjectBrowser); + /// Returns the viewer Z layer + int getVisualLayerId() const { return myVisualLayerId; } + public slots: /// SLOT, that is called by no more widget signal emitted by property panel /// Set a specific flag to restart the sketcher operation diff --git a/src/PartSet/PartSet_OperationPrs.cpp b/src/PartSet/PartSet_OperationPrs.cpp index 4539ebbd2..1f9bd11b5 100755 --- a/src/PartSet/PartSet_OperationPrs.cpp +++ b/src/PartSet/PartSet_OperationPrs.cpp @@ -5,101 +5,168 @@ // Author: Natalia ERMOLAEVA #include "PartSet_OperationPrs.h" +#include "PartSet_Tools.h" -//#include -//#include -//#include +#include +#include +#include +#include +#include +#include +#include -//#include -//#include -//#include +#include + +#include IMPLEMENT_STANDARD_HANDLE(PartSet_OperationPrs, ViewerData_AISShape); IMPLEMENT_STANDARD_RTTIEXT(PartSet_OperationPrs, ViewerData_AISShape); -PartSet_OperationPrs::PartSet_OperationPrs() - : ViewerData_AISShape(TopoDS_Shape()), myFeature(FeaturePtr()) +PartSet_OperationPrs::PartSet_OperationPrs(ModuleBase_IWorkshop* theWorkshop) + : ViewerData_AISShape(TopoDS_Shape()), myFeature(FeaturePtr()), myWorkshop(theWorkshop) { } -void PartSet_OperationPrs::setFeature(FeaturePtr theFeature) +bool PartSet_OperationPrs::canActivate(const FeaturePtr& theFeature) { -/* std::shared_ptr aShapePtr = ModelAPI_Tools::shape(theResult); - std::shared_ptr aWirePtr = - std::dynamic_pointer_cast(aShapePtr); - if (aWirePtr) { - if (aWirePtr->hasPlane() ) { - // If this is a wire with plane defined thin it is a sketch-like object - // It must have invisible faces - myIsSketchMode = true; - } - } - Set(aShapePtr->impl()); -*/ + bool aHasSelectionAttribute = false; + + std::list anAttributes = theFeature->data()->attributes(""); + std::list::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end(); + for (; anIt != aLast && !aHasSelectionAttribute; anIt++) + aHasSelectionAttribute = isSelectionAttribute(*anIt); + + return aHasSelectionAttribute; } +void PartSet_OperationPrs::setFeature(const FeaturePtr& theFeature) +{ + myFeature = theFeature; + updateShapes(); +} + +bool PartSet_OperationPrs::dependOn(const ObjectPtr& theResult) +{ + return myFeatureShapes.contains(theResult); +} + +void PartSet_OperationPrs::updateShapes() +{ + myFeatureShapes.clear(); + getFeatureShapes(myFeatureShapes); +} -/*#include -#include -#include -#include -*/ void PartSet_OperationPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode) { -/* std::shared_ptr aShapePtr = ModelAPI_Tools::shape(myResult); - if (!aShapePtr) - return; - if (myIsSketchMode) { - myFacesList.clear(); - ResultConstructionPtr aConstruction = - std::dynamic_pointer_cast(myResult); - if (aConstruction.get()) { - int aFacesNum = aConstruction->facesNum(); - for(int aFaceIndex = 0; aFaceIndex < aFacesNum; aFaceIndex++) { - myFacesList.push_back(aConstruction->face(aFaceIndex)); - } + thePresentation->Clear(); + + // create presentations on the base of the shapes + Handle(Prs3d_Drawer) aDrawer = Attributes(); + QMap >::const_iterator anIt = myFeatureShapes.begin(), + aLast = myFeatureShapes.end(); + for (; anIt != aLast; anIt++) { + QList aShapes = anIt.value(); + QList::const_iterator aShIt = aShapes.begin(), aShLast = aShapes.end(); + for (; aShIt != aShLast; aShIt++) { + GeomShapePtr aGeomShape = *aShIt; + TopoDS_Shape aShape = aGeomShape->impl(); + StdPrs_WFDeflectionShape::Add(thePresentation, aShape, aDrawer); } } - myOriginalShape = aShapePtr->impl(); - if (!myOriginalShape.IsNull()) { - Set(myOriginalShape); - - AIS_Shape::Compute(thePresentationManager, thePresentation, theMode); - /* - TopExp_Explorer anExp(myOriginalShape, TopAbs_VERTEX); - Handle(Prs3d_Drawer) aDrawer = Attributes(); - for (; anExp.More(); anExp.Next()) { - const TopoDS_Vertex& aVertex = (const TopoDS_Vertex&)anExp.Current(); - StdPrs_WFDeflectionShape::Add(thePresentation, aVertex, aDrawer); - }*|/ - }*/ } - void PartSet_OperationPrs::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, const Standard_Integer aMode) { -/* if (aMode > TopAbs_SHAPE) - // In order to avoid using custom selection modes + // the presentation is not used in the selection +} + +void addValue(const ObjectPtr& theObject, const GeomShapePtr& theShape, + QMap >& theObjectShapes) +{ + if (theObjectShapes.contains(theObject)) + theObjectShapes[theObject].append(theShape); + else { + QList aShapes; + aShapes.append(theShape); + theObjectShapes[theObject] = aShapes; + } +} + +void PartSet_OperationPrs::getFeatureShapes(QMap >& theObjectShapes) +{ + if (!myFeature.get()) return; - if (myIsSketchMode) { - if (aMode == TopAbs_FACE) { - BRep_Builder aBuilder; - TopoDS_Compound aComp; - aBuilder.MakeCompound(aComp); - aBuilder.Add(aComp, myOriginalShape); - std::list>::const_iterator aIt; - for (aIt = myFacesList.cbegin(); aIt != myFacesList.cend(); ++aIt) { - TopoDS_Shape aFace = (*aIt)->impl(); - aBuilder.Add(aComp, aFace); + QList aShapes; + std::list anAttributes = myFeature->data()->attributes(""); + std::list::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end(); + for (; anIt != aLast; anIt++) { + AttributePtr anAttribute = *anIt; + if (!isSelectionAttribute(anAttribute)) + continue; + + std::string anAttrType = anAttribute->attributeType(); + + if (anAttrType == ModelAPI_AttributeSelectionList::typeId()) { + std::shared_ptr aCurSelList = + std::dynamic_pointer_cast(anAttribute); + for(int i = 0; i < aCurSelList->size(); i++) { + std::shared_ptr aSelAttribute = aCurSelList->value(i); + ResultPtr aResult = aSelAttribute->context(); + GeomShapePtr aShape = aSelAttribute->value(); + if (!aShape.get()) + aShape = aResult->shape(); + addValue(aResult, aShape, theObjectShapes); + } + } + else { + ObjectPtr anObject; + GeomShapePtr aShape; + if (anAttrType == ModelAPI_AttributeRefAttr::typeId()) { + AttributeRefAttrPtr anAttr = std::dynamic_pointer_cast(anAttribute); + if (anAttr->isObject()) { + anObject = anAttr->object(); + } + else { + aShape = PartSet_Tools::findShapeBy2DPoint(anAttr, myWorkshop); + // the distance point is not found if the point is selected in the 2nd time + // TODO: after debug, this check can be removed + if (!aShape.get()) + continue; + anObject = anAttr->attr()->owner(); + } + } + if (anAttrType == ModelAPI_AttributeSelection::typeId()) { + AttributeSelectionPtr anAttr = std::dynamic_pointer_cast(anAttribute); + anObject = anAttr->context(); + aShape = anAttr->value(); + } + if (anAttrType == ModelAPI_AttributeReference::typeId()) { + AttributeReferencePtr anAttr = std::dynamic_pointer_cast(anAttribute); + anObject = anAttr->value(); + } + + if (anObject.get()) { + if (!aShape.get()) { + ResultPtr aResult = std::dynamic_pointer_cast(anObject); + if (aResult.get()) + aShape = aResult->shape(); + } + addValue(anObject, aShape, theObjectShapes); } - Set(aComp); - } else { - Set(myOriginalShape); } - }*/ - AIS_Shape::ComputeSelection(aSelection, aMode); -} \ No newline at end of file + } +} + +bool PartSet_OperationPrs::isSelectionAttribute(const AttributePtr& theAttribute) +{ + std::string anAttrType = theAttribute->attributeType(); + + return anAttrType == ModelAPI_AttributeSelectionList::typeId() || + anAttrType == ModelAPI_AttributeRefAttr::typeId() || + anAttrType == ModelAPI_AttributeSelection::typeId() || + anAttrType == ModelAPI_AttributeReference::typeId(); +} diff --git a/src/PartSet/PartSet_OperationPrs.h b/src/PartSet/PartSet_OperationPrs.h index e15365101..e296e7b1d 100755 --- a/src/PartSet/PartSet_OperationPrs.h +++ b/src/PartSet/PartSet_OperationPrs.h @@ -9,30 +9,50 @@ #include "PartSet.h" -#include +#include #include +#include + +#include + +#include #include #include +#include +#include + DEFINE_STANDARD_HANDLE(PartSet_OperationPrs, ViewerData_AISShape) /** * \ingroup GUI -* A redefinition of standard AIS Interactive Object in order to provide specific behaviour -* for wire presentations based in a one plane +* A redefinition of standard AIS Interactive Object in order to provide colored presentation of +* a list of shapes. It contains a shapes where the parameter feature refers. It processes the following +* types of attributes: ModelAPI_AttributeSelectionList, ModelAPI_AttributeRefAttr, +* ModelAPI_AttributeSelection and ModelAPI_AttributeReference. +* The selection for this presentation is absent. */ class PartSet_OperationPrs : public ViewerData_AISShape { public: /// Constructor - /// \param theResult a result object - Standard_EXPORT PartSet_OperationPrs(); + Standard_EXPORT PartSet_OperationPrs(ModuleBase_IWorkshop* theWorkshop); + + /// Returns true if the feature contains attributes, which has references to other features + /// \param theFeature a feature + /// \return boolean result + bool canActivate(const FeaturePtr& theFeature); - /// set the operation feature. It is used in Compute method to group the feature parameter shapes + /// Sets the operation feature. It is used in Compute method to group the feature parameter shapes /// theFeature a feature - void setFeature(FeaturePtr theFeature); + void setFeature(const FeaturePtr& theFeature); + /// Returns true if the presentation + bool dependOn(const ObjectPtr& theObject); + + // Recompute internal list of shaped dependent on the current feature + void updateShapes(); DEFINE_STANDARD_RTTI(PartSet_OperationPrs) @@ -46,8 +66,20 @@ protected: Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, const Standard_Integer aMode) ; private: - /// Reference to a feature object - FeaturePtr myFeature; + /// Fills the map by the feature object and shapes, which should be visuaziled + /// Gets the feature attribute, collect objects to whom the attribute refers + /// \param theObjectShape an output map of objects + void getFeatureShapes(QMap >& theObjectShapes); + + /// Returns true if the attribute type belong to reference attribute + /// \param theAttribute an attribute + /// \return a boolean value + static bool isSelectionAttribute(const AttributePtr& theAttribute); + +private: + ModuleBase_IWorkshop* myWorkshop; + FeaturePtr myFeature; /// Reference to a feature object + QMap > myFeatureShapes; }; diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index e0c1940c9..1385c0970 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -290,12 +290,6 @@ void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel() void PartSet_SketcherMgr::onValuesChangedInPropertyPanel() { - ModuleBase_Operation* anOperation = getCurrentOperation(); - bool isSketchOp = isSketchOperation(anOperation); - bool isNestedSketchOp = isNestedSketchOperation(anOperation); - if (isSketchOp || isNestedSketchOp) - myModule->setCustomized(anOperation->feature()); - if (!isNestedCreateOperation(getCurrentOperation())) return; @@ -824,7 +818,6 @@ void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation) onShowConstraintsToggle(true); } connectToPropertyPanel(true); - myModule->setCustomized(getCurrentOperation()->feature()); } void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp) @@ -833,8 +826,6 @@ void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp) myIsResetCurrentValue = false; myIsMouseOverViewProcessed = true; operationMgr()->onValidateOperation(); - - myModule->setCustomized(FeaturePtr()); } void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation) diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index f5dbff318..843bda304 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -5,6 +5,8 @@ // Author: Natalia ERMOLAEVA #include +#include +#include #include #include @@ -13,6 +15,12 @@ #include #include +#include +#include +#include +#include +#include + #include #include #include @@ -38,6 +46,7 @@ #include #include +#include #include #include @@ -51,6 +60,9 @@ #include #include #include +#include +#include +#include #ifdef _DEBUG #include @@ -632,6 +644,63 @@ bool PartSet_Tools::hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePt return aHasVertex; } +GeomShapePtr PartSet_Tools::findShapeBy2DPoint(const AttributePtr& theAttribute, + ModuleBase_IWorkshop* theWorkshop) +{ + // 1. find an attribute value in attribute reference attribute value + GeomShapePtr aShape; + AttributeRefAttrPtr aRefAttr = + std::dynamic_pointer_cast(theAttribute); + if (aRefAttr) { + if (!aRefAttr->isObject()) { + AttributePtr theAttribute = aRefAttr->attr(); + if (theAttribute.get()) { + XGUI_ModuleConnector* aConnector = dynamic_cast(theWorkshop); + XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); + + // 2. find visualized vertices of the attribute and if the attribute of the vertex is + // the same, return it + FeaturePtr anAttributeFeature = ModelAPI_Feature::feature(theAttribute->owner()); + // 2.1 get visualized results of the feature + const std::list& aResList = anAttributeFeature->results(); + std::list::const_iterator anIt = aResList.begin(), aLast = aResList.end(); + for (; anIt != aLast; anIt++) { + AISObjectPtr aAISObj = aDisplayer->getAISObject(*anIt); + if (aAISObj.get() != NULL) { + Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl(); + // 2.2 find selected owners of a visualizedd object + SelectMgr_IndexedMapOfOwner aSelectedOwners; + aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners); + for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) { + Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i); + if (!anOwner.IsNull()) { + Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(anOwner); + if (!aBRepOwner.IsNull() && aBRepOwner->HasShape()) { + const TopoDS_Shape& aBRepShape = aBRepOwner->Shape(); + if (aBRepShape.ShapeType() == TopAbs_VERTEX) { + // 2.3 if the owner is vertex and an attribute of the vertex is equal to the initial + // attribute, returns the shape + PartSet_Module* aModule = dynamic_cast(theWorkshop->module()); + PartSet_SketcherMgr* aSketchMgr = aModule->sketchMgr(); + AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(anAttributeFeature, + aBRepShape, aSketchMgr->activeSketch()); + if (aPntAttr.get() != NULL && aPntAttr == theAttribute) { + aShape = std::shared_ptr(new GeomAPI_Shape); + aShape->setImpl(new TopoDS_Shape(aBRepShape)); + break; + } + } + } + } + } + } + } + } + } + } + return aShape; +} + AttributePtr PartSet_Tools::findAttributeBy2dPoint(ObjectPtr theObj, const TopoDS_Shape theShape, FeaturePtr theSketch) diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index 1aaf66401..54c8b8978 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -25,6 +25,7 @@ class Handle_V3d_View; class ModuleBase_ViewerPrs; +class ModuleBase_IWorkshop; class GeomDataAPI_Point2D; class GeomAPI_Pln; class GeomAPI_Pnt2d; @@ -205,7 +206,16 @@ class PARTSET_EXPORT PartSet_Tools * \param theShape - a Shape * \param theSketch - a Sketch to get a plane of converting to 2d */ - static AttributePtr findAttributeBy2dPoint(ObjectPtr theObj, const TopoDS_Shape theShape, FeaturePtr theSketch); + static AttributePtr findAttributeBy2dPoint(ObjectPtr theObj, const TopoDS_Shape theShape, + FeaturePtr theSketch); + + /** + * Finds an attribute value in attribute reference attribute value + * \param theAttribute - an attribure reference filled with an attribute + * \return a geometry shape + */ + static GeomShapePtr findShapeBy2DPoint(const AttributePtr& theAttribute, + ModuleBase_IWorkshop* theWorkshop); protected: /// Returns an object that is under the mouse point. Firstly it checks the highlighting, diff --git a/src/PartSet/PartSet_WidgetShapeSelector.cpp b/src/PartSet/PartSet_WidgetShapeSelector.cpp index ae4a29512..488a26568 100644 --- a/src/PartSet/PartSet_WidgetShapeSelector.cpp +++ b/src/PartSet/PartSet_WidgetShapeSelector.cpp @@ -109,58 +109,10 @@ void PartSet_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrs& t GeomShapePtr PartSet_WidgetShapeSelector::getShape() const { // an empty shape by default - GeomShapePtr aShape; - - // 1. find an attribute value in attribute reference attribute value DataPtr aData = myFeature->data(); - AttributePtr aAttr = aData->attribute(attributeID()); - AttributeRefAttrPtr aRefAttr = - std::dynamic_pointer_cast(aAttr); - if (aRefAttr) { - if (!aRefAttr->isObject()) { - AttributePtr anAttribute = aRefAttr->attr(); - if (anAttribute.get()) { - XGUI_ModuleConnector* aConnector = dynamic_cast(myWorkshop); - XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); - - // 2. find visualized vertices of the attribute and if the attribute of the vertex is - // the same, return it - FeaturePtr anAttributeFeature = ModelAPI_Feature::feature(anAttribute->owner()); - // 2.1 get visualized results of the feature - const std::list& aResList = anAttributeFeature->results(); - std::list::const_iterator anIt = aResList.begin(), aLast = aResList.end(); - for (; anIt != aLast; anIt++) { - AISObjectPtr aAISObj = aDisplayer->getAISObject(*anIt); - if (aAISObj.get() != NULL) { - Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl(); - // 2.2 find selected owners of a visualizedd object - SelectMgr_IndexedMapOfOwner aSelectedOwners; - aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners); - for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) { - Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i); - if (!anOwner.IsNull()) { - Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(anOwner); - if (!aBRepOwner.IsNull() && aBRepOwner->HasShape()) { - const TopoDS_Shape& aBRepShape = aBRepOwner->Shape(); - if (aBRepShape.ShapeType() == TopAbs_VERTEX) { - // 2.3 if the owner is vertex and an attribute of the vertex is equal to the initial - // attribute, returns the shape - AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(anAttributeFeature, - aBRepShape, sketch()); - if (aPntAttr.get() != NULL && aPntAttr == anAttribute) { - aShape = std::shared_ptr(new GeomAPI_Shape); - aShape->setImpl(new TopoDS_Shape(aBRepShape)); - break; - } - } - } - } - } - } - } - } - } - } + AttributePtr anAttribute = aData->attribute(attributeID()); + GeomShapePtr aShape = PartSet_Tools::findShapeBy2DPoint(anAttribute, myWorkshop); + if (!aShape.get()) aShape = ModuleBase_WidgetShapeSelector::getShape(); return aShape; diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index efd6481ec..c202b4f6d 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -861,6 +861,7 @@ bool XGUI_Displayer::customizeObject(ObjectPtr theObject) ResultPtr aResult = std::dynamic_pointer_cast(theObject); // Customization of presentation + bool isPresentable = false; GeomCustomPrsPtr aCustomPrs; FeaturePtr aFeature = ModelAPI_Feature::feature(theObject); if (aFeature.get() != NULL) { @@ -871,11 +872,12 @@ bool XGUI_Displayer::customizeObject(ObjectPtr theObject) if (aCustomPrs.get() == NULL) { // we ignore presentable not customized objects GeomPresentablePtr aPrs = std::dynamic_pointer_cast(theObject); - if (aPrs.get() != NULL) - return false; + isPresentable = aPrs.get() != NULL; aCustomPrs = myCustomPrs; } - bool isCustomized = aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs); + bool isCustomized = false; + if (!isPresentable) + aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs); isCustomized = myWorkshop->module()->customizeObject(theObject) || isCustomized; return isCustomized; } -- 2.39.2