Crash fix in sketch manager when find a dected owner.
/// \param theModes a list of modes\r
virtual void activeSelectionModes(QIntList& theModes) {}\r
\r
+ /** Update the object presentable properties such as color, lines width and other\r
+ * If the object is result with the color attribute value set, it is used,\r
+ * otherwise the customize is applyed to the object's feature if it is a custom prs\r
+ * \param theObject an object instance\r
+ * \return the true state if there is changes and the presentation is customized\r
+ */\r
+ virtual bool customizeObject(ObjectPtr theObject) { return false; }\r
+\r
/// This method is called on object browser creation for customisation of module specific features\r
/// \param theObjectBrowser a pinter on Object Browser widget\r
virtual void customizeObjectBrowser(QWidget* theObjectBrowser) {}\r
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
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
PartSet_FilterInfinite.cpp
PartSet_SketcherMgr.cpp
PartSet_MenuMgr.cpp
- PartSet_DocumentDataModel.cpp
- PartSet_PartDataModel.cpp
+ PartSet_DocumentDataModel.cpp
+ PartSet_PartDataModel.cpp
PartSet_WidgetSketchCreator.cpp
)
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: PartSet_CustomPrs.cpp
+// Created: 30 Jun 2015
+// Author: Natalia ERMOLAEVA
+
+#include <PartSet_CustomPrs.h>
+
+#include <XGUI_ModuleConnector.h>
+#include <XGUI_Workshop.h>
+#include <XGUI_Displayer.h>
+
+#include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_IViewer.h>
+
+#include <GeomValidators_Tools.h>
+
+#include <ModelAPI_Attribute.h>
+#include <ModelAPI_AttributeSelectionList.h>
+
+#include <Config_PropManager.h>
+
+#include <AIS_InteractiveContext.hxx>
+
+#define OPERATION_PARAMETER_COLOR "255, 255, 0"
+
+PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop)
+ : myWorkshop(theWorkshop)
+{
+}
+
+void PartSet_CustomPrs::setCustomized(const ObjectPtr& theObject)
+{
+/* QMap<ResultPtr, QList<GeomShapePtr> > aNewCustomized;
+
+ QList<GeomShapePtr> aShapeList;
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+ if (aResult.get()) {
+ aNewCustomized[aResult] = aShapeList;
+ }
+ else {
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+ if (aFeature.get()) {
+ std::list<AttributePtr> anAttributes = aFeature->data()->attributes("");
+ std::list<AttributePtr>::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<ModelAPI_Result>(anObject);
+ if (aResult.get())
+ aNewCustomized[aResult] = aShapeList;
+ }
+ else if (anAttribute->attributeType() == ModelAPI_AttributeSelectionList::typeId()) {
+ std::shared_ptr<ModelAPI_AttributeSelectionList> aCurSelList =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(anAttribute);
+ for(int i = 0; i < aCurSelList->size(); i++) {
+ std::shared_ptr<ModelAPI_AttributeSelection> aSelAttribute = aCurSelList->value(i);
+ ObjectPtr anObject = GeomValidators_Tools::getObject(aSelAttribute);
+ if (anObject.get()) {
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+ if (aResult.get())
+ aNewCustomized[aResult] = aShapeList;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ bool isDone = false;
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(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<ResultPtr, QList<GeomShapePtr> > aNotCustomized;
+ QMap<ResultPtr, QList<GeomShapePtr> >::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<Handle(AIS_InteractiveObject)>();
+ 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 <AIS_InteractiveObject.hxx>
+#include <AIS_Shape.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <StdPrs_ShadedShape.hxx>
+#include <StdPrs_WFDeflectionShape.hxx>*/
+bool PartSet_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
+ std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
+{
+ bool isDone = false;
+ if (myCustomized.contains(theResult)) {
+ std::vector<int> 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<Handle(AIS_InteractiveObject)>();
+
+ 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<int> 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;
+}
--- /dev/null
+// 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 <ModelAPI_Object.h>
+#include <ModelAPI_Result.h>
+
+#include <GeomAPI_ICustomPrs.h>
+#include <GeomAPI_AISObject.h>
+#include <GeomAPI_Shape.h>
+
+#include <QMap>
+#include <QList>
+
+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<GeomAPI_ICustomPrs> theCustomPrs);
+private:
+ ModuleBase_IWorkshop* myWorkshop; /// current workshop
+
+ QMap<ResultPtr, QList<GeomShapePtr> > myCustomized; /// objects, which are customized
+};
+
+#endif
#include "PartSet_WidgetSketchCreator.h"
#include "PartSet_SketcherMgr.h"
#include "PartSet_MenuMgr.h"
+#include <PartSet_CustomPrs.h>
#include "PartSet_Filters.h"
#include "PartSet_FilterInfinite.h"
SLOT(onViewTransformed(int)));
myMenuMgr = new PartSet_MenuMgr(this);
+ myCustomPrs = std::shared_ptr<GeomAPI_ICustomPrs>(new PartSet_CustomPrs(theWshop));
Events_Loop* aLoop = Events_Loop::loop();
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
aDisplayer->updateViewer();
}
+void PartSet_Module::setCustomized(const ObjectPtr& theObject)
+{
+ std::shared_ptr<PartSet_CustomPrs> aCustomPrs =
+ std::dynamic_pointer_cast<PartSet_CustomPrs>(myCustomPrs);
+ if (aCustomPrs.get())
+ aCustomPrs->setCustomized(theObject);
+}
+
+bool PartSet_Module::customizeObject(ObjectPtr theObject)
+{
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(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)
{
#include <ModelAPI_Attribute.h>
#include <ModelAPI_CompositeFeature.h>
+#include <GeomAPI_ICustomPrs.h>
+
#include <Events_Listener.h>
//#include <StdSelect_FaceFilter.hxx>
/// \param theMessage an event message
virtual void processEvent(const std::shared_ptr<Events_Message>& 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);
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;
--- /dev/null
+// 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 <ModelAPI_Tools.h>
+#include <ModelAPI_ResultConstruction.h>
+#include <GeomAPI_PlanarEdges.h>
+
+#include <BRep_Builder.hxx>
+#include <Prs3d_IsoAspect.hxx>
+#include <TopoDS_Builder.hxx>
+
+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<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(theResult);
+ std::shared_ptr<GeomAPI_PlanarEdges> aWirePtr =
+ std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(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<TopoDS_Shape>());
+*/
+}
+
+
+/*#include <TopExp_Explorer.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <StdPrs_ShadedShape.hxx>
+#include <StdPrs_WFDeflectionShape.hxx>
+*/
+void PartSet_OperationPrs::Compute(const Handle(PrsMgr_PresentationManager3d)& thePresentationManager,
+ const Handle(Prs3d_Presentation)& thePresentation,
+ const Standard_Integer theMode)
+{
+/* std::shared_ptr<GeomAPI_Shape> aShapePtr = ModelAPI_Tools::shape(myResult);
+ if (!aShapePtr)
+ return;
+ if (myIsSketchMode) {
+ myFacesList.clear();
+ ResultConstructionPtr aConstruction =
+ std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(myResult);
+ if (aConstruction.get()) {
+ int aFacesNum = aConstruction->facesNum();
+ for(int aFaceIndex = 0; aFaceIndex < aFacesNum; aFaceIndex++) {
+ myFacesList.push_back(aConstruction->face(aFaceIndex));
+ }
+ }
+ }
+ myOriginalShape = aShapePtr->impl<TopoDS_Shape>();
+ 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<std::shared_ptr<GeomAPI_Shape>>::const_iterator aIt;
+ for (aIt = myFacesList.cbegin(); aIt != myFacesList.cend(); ++aIt) {
+ TopoDS_Shape aFace = (*aIt)->impl<TopoDS_Shape>();
+ aBuilder.Add(aComp, aFace);
+ }
+ Set(aComp);
+ } else {
+ Set(myOriginalShape);
+ }
+ }*/
+ AIS_Shape::ComputeSelection(aSelection, aMode);
+}
\ No newline at end of file
--- /dev/null
+// 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 <ModelAPI_Result.h>
+#include <ModelAPI_Feature.h>
+
+#include <ViewerData_AISShape.hxx>
+#include <Standard_DefineHandle.hxx>
+
+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
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;
onShowConstraintsToggle(true);
}
connectToPropertyPanel(true);
+ myModule->setCustomized(getCurrentOperation()->feature());
}
void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOp)
myIsResetCurrentValue = false;
myIsMouseOverViewProcessed = true;
operationMgr()->onValidateOperation();
+
+ myModule->setCustomized(ObjectPtr());
}
void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
}
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,
#include <ModuleBase_ResultPrs.h>
#include <ModuleBase_Tools.h>
+#include <ModuleBase_IModule.h>
#include <GeomAPI_Shape.h>
#include <GeomAPI_IPresentable.h>
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;
}