From: nds Date: Wed, 1 Jul 2015 12:01:49 +0000 (+0300) Subject: Issue #591 - Highlight of the first argument of constraints X-Git-Tag: V_1.3.0~134 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1599bc97cf8f4eb2b4154586fe16c2f3b7a3895e;p=modules%2Fshaper.git Issue #591 - Highlight of the first argument of constraints Crash fix in sketch manager when find a dected owner. --- diff --git a/src/ModuleBase/ModuleBase_IModule.h b/src/ModuleBase/ModuleBase_IModule.h index bea23dbcd..1ef962d28 100644 --- a/src/ModuleBase/ModuleBase_IModule.h +++ b/src/ModuleBase/ModuleBase_IModule.h @@ -144,6 +144,14 @@ class MODULEBASE_EXPORT ModuleBase_IModule : public QObject /// \param theModes a list of modes virtual void activeSelectionModes(QIntList& theModes) {} + /** Update the object presentable properties such as color, lines width and other + * If the object is result with the color attribute value set, it is used, + * otherwise the customize is applyed to the object's feature if it is a custom prs + * \param theObject an object instance + * \return the true state if there is changes and the presentation is customized + */ + virtual bool customizeObject(ObjectPtr theObject) { return false; } + /// This method is called on object browser creation for customisation of module specific features /// \param theObjectBrowser a pinter on Object Browser widget virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {} diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index f86ae4385..1a9d16288 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -7,8 +7,10 @@ SET(CMAKE_AUTOMOC ON) SET(PROJECT_HEADERS PartSet.h PartSet_Constants.h + PartSet_CustomPrs.h PartSet_ExternalObjectsMgr.h PartSet_Module.h + PartSet_OperationPrs.h PartSet_Tools.h PartSet_WidgetSketchLabel.h PartSet_Validators.h @@ -24,15 +26,17 @@ SET(PROJECT_HEADERS PartSet_FilterInfinite.h PartSet_SketcherMgr.h PartSet_MenuMgr.h - PartSet_DocumentDataModel.h - PartSet_PartDataModel.h - PartSet_DataTreeModel.h + PartSet_DocumentDataModel.h + PartSet_PartDataModel.h + PartSet_DataTreeModel.h PartSet_WidgetSketchCreator.h ) SET(PROJECT_SOURCES + PartSet_CustomPrs.cpp PartSet_ExternalObjectsMgr.cpp PartSet_Module.cpp + PartSet_OperationPrs.cpp PartSet_Tools.cpp PartSet_WidgetSketchLabel.cpp PartSet_Validators.cpp @@ -48,8 +52,8 @@ SET(PROJECT_SOURCES PartSet_FilterInfinite.cpp PartSet_SketcherMgr.cpp PartSet_MenuMgr.cpp - PartSet_DocumentDataModel.cpp - PartSet_PartDataModel.cpp + PartSet_DocumentDataModel.cpp + PartSet_PartDataModel.cpp PartSet_WidgetSketchCreator.cpp ) diff --git a/src/PartSet/PartSet_CustomPrs.cpp b/src/PartSet/PartSet_CustomPrs.cpp new file mode 100755 index 000000000..3ae846074 --- /dev/null +++ b/src/PartSet/PartSet_CustomPrs.cpp @@ -0,0 +1,156 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: PartSet_CustomPrs.cpp +// Created: 30 Jun 2015 +// Author: Natalia ERMOLAEVA + +#include + +#include +#include +#include + +#include +#include + +#include + +#include +#include + +#include + +#include + +#define OPERATION_PARAMETER_COLOR "255, 255, 0" + +PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop) + : myWorkshop(theWorkshop) +{ +} + +void PartSet_CustomPrs::setCustomized(const ObjectPtr& theObject) +{ +/* QMap > aNewCustomized; + + 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; + } + } + } + } + } + } + + 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; + } + + 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); + } + + // 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; + } + if (isDone) + aDisplayer->updateViewer();*/ +} + +/*#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; +} diff --git a/src/PartSet/PartSet_CustomPrs.h b/src/PartSet/PartSet_CustomPrs.h new file mode 100755 index 000000000..df17bea09 --- /dev/null +++ b/src/PartSet/PartSet_CustomPrs.h @@ -0,0 +1,45 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: PartSet_CustomPrs.hxx +// Created: 30 Jun 2015 +// Author: Natalia ERMOLAEVA + +#ifndef PartSet_CustomPrs_H +#define PartSet_CustomPrs_H + +#include "PartSet.h" + +#include +#include + +#include +#include +#include + +#include +#include + +class ModuleBase_IWorkshop; + +/** +* Interface of a class which can provide specific customization of +* object presentation +*/ +class PartSet_CustomPrs : public GeomAPI_ICustomPrs +{ +public: + PARTSET_EXPORT PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop); + PARTSET_EXPORT virtual ~PartSet_CustomPrs() {}; + + void setCustomized(const ObjectPtr& theObject); + + /// Modifies the given presentation in the custom way. + virtual bool customisePresentation(ResultPtr theResult, AISObjectPtr thePrs, + std::shared_ptr theCustomPrs); +private: + ModuleBase_IWorkshop* myWorkshop; /// current workshop + + QMap > myCustomized; /// objects, which are customized +}; + +#endif diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 1eaed276a..e6ee9c5b7 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -14,6 +14,7 @@ #include "PartSet_WidgetSketchCreator.h" #include "PartSet_SketcherMgr.h" #include "PartSet_MenuMgr.h" +#include #include "PartSet_Filters.h" #include "PartSet_FilterInfinite.h" @@ -131,6 +132,7 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop) SLOT(onViewTransformed(int))); myMenuMgr = new PartSet_MenuMgr(this); + myCustomPrs = std::shared_ptr(new PartSet_CustomPrs(theWshop)); Events_Loop* aLoop = Events_Loop::loop(); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED)); @@ -718,6 +720,25 @@ void PartSet_Module::onViewTransformed(int theTrsfType) aDisplayer->updateViewer(); } +void PartSet_Module::setCustomized(const ObjectPtr& theObject) +{ + std::shared_ptr aCustomPrs = + std::dynamic_pointer_cast(myCustomPrs); + if (aCustomPrs.get()) + aCustomPrs->setCustomized(theObject); +} + +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); +} void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser) { diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index d6c2d4786..3f9dd010e 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -12,6 +12,8 @@ #include #include +#include + #include //#include @@ -142,6 +144,18 @@ public: /// \param theMessage an event message virtual void processEvent(const std::shared_ptr& theMessage); + /// Set the object with the object results are customized + /// \param theObject an object + void setCustomized(const ObjectPtr& theObject); + + /** Update the object presentable properties such as color, lines width and other + * If the object is result with the color attribute value set, it is used, + * otherwise the customize is applyed to the object's feature if it is a custom prs + * \param theObject an object instance + * \return the true state if there is changes and the presentation is customized + */ + virtual bool customizeObject(ObjectPtr theObject); + /// This method is called on object browser creation for customisation of module specific features /// \param theObjectBrowser a pinter on Object Browser widget virtual void customizeObjectBrowser(QWidget* theObjectBrowser); @@ -215,8 +229,9 @@ protected slots: SelectMgr_ListOfFilter mySelectionFilters; PartSet_SketcherMgr* mySketchMgr; - PartSet_MenuMgr* myMenuMgr; + /// A default custom presentation, which is used for references objects of started operation + GeomCustomPrsPtr myCustomPrs; int myVisualLayerId; diff --git a/src/PartSet/PartSet_OperationPrs.cpp b/src/PartSet/PartSet_OperationPrs.cpp new file mode 100755 index 000000000..6bcdb1c16 --- /dev/null +++ b/src/PartSet/PartSet_OperationPrs.cpp @@ -0,0 +1,101 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: PartSet_OperationPrs.cpp +// Created: 01 Jul 2015 +// Author: Natalia ERMOLAEVA + +#include "PartSet_OperationPrs.h" + +#include +#include +#include + +#include +#include +#include + +IMPLEMENT_STANDARD_HANDLE(PartSet_OperationPrs, ViewerData_AISShape); +IMPLEMENT_STANDARD_RTTIEXT(PartSet_OperationPrs, ViewerData_AISShape); + +PartSet_OperationPrs::PartSet_OperationPrs(FeaturePtr theFeature) + : ViewerData_AISShape(TopoDS_Shape()), myFeature(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()); +*/ +} + + +/*#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)); + } + } + } + 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 + 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); + } + Set(aComp); + } else { + Set(myOriginalShape); + } + }*/ + AIS_Shape::ComputeSelection(aSelection, aMode); +} \ No newline at end of file diff --git a/src/PartSet/PartSet_OperationPrs.h b/src/PartSet/PartSet_OperationPrs.h new file mode 100755 index 000000000..9d2cc93b0 --- /dev/null +++ b/src/PartSet/PartSet_OperationPrs.h @@ -0,0 +1,48 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: PartSet_OperationPrs.h +// Created: 01 Jul 2015 +// Author: Natalia ERMOLAEVA + +#ifndef PartSet_OperationPrs_H +#define PartSet_OperationPrs_H + +#include "PartSet.h" + +#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 +*/ +class PartSet_OperationPrs : public ViewerData_AISShape +{ +public: + /// Constructor + /// \param theResult a result object + Standard_EXPORT PartSet_OperationPrs(FeaturePtr theFeature); + + DEFINE_STANDARD_RTTI(PartSet_OperationPrs) +protected: + /// Redefinition of virtual function + Standard_EXPORT virtual void Compute( + const Handle(PrsMgr_PresentationManager3d)& thePresentationManager, + const Handle(Prs3d_Presentation)& thePresentation, const Standard_Integer theMode = 0); + + /// Redefinition of virtual function + Standard_EXPORT virtual void ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, + const Standard_Integer aMode) ; +private: + /// Reference to a feature object + FeaturePtr myFeature; +}; + + +#endif \ No newline at end of file diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 067dc093a..cb21c0190 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -290,6 +290,12 @@ 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; @@ -818,6 +824,7 @@ void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation) onShowConstraintsToggle(true); } connectToPropertyPanel(true); + myModule->setCustomized(getCurrentOperation()->feature()); } void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp) @@ -826,6 +833,8 @@ void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp) myIsResetCurrentValue = false; myIsMouseOverViewProcessed = true; operationMgr()->onValidateOperation(); + + myModule->setCustomized(ObjectPtr()); } void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation) @@ -994,6 +1003,8 @@ void PartSet_SketcherMgr::getCurrentSelection(const FeaturePtr& theFeature, } for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) { Handle(SelectMgr_EntityOwner) anOwner = aContext->DetectedOwner(); + if (anOwner.IsNull()) + continue; if (anOwner->Selectable() != anAISIO) continue; getAttributesOrResults(anOwner, theFeature, theSketch, aResult, diff --git a/src/XGUI/XGUI_Displayer.cpp b/src/XGUI/XGUI_Displayer.cpp index 5e76cf201..efd6481ec 100644 --- a/src/XGUI/XGUI_Displayer.cpp +++ b/src/XGUI/XGUI_Displayer.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -874,7 +875,9 @@ bool XGUI_Displayer::customizeObject(ObjectPtr theObject) return false; aCustomPrs = myCustomPrs; } - return aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs); + bool isCustomized = aCustomPrs->customisePresentation(aResult, anAISObj, myCustomPrs); + isCustomized = myWorkshop->module()->customizeObject(theObject) || isCustomized; + return isCustomized; }