// Author: Natalia ERMOLAEVA
#include <PartSet_CustomPrs.h>
+#include <PartSet_Module.h>
+#include "PartSet_OperationPrs.h"
#include <XGUI_ModuleConnector.h>
#include <XGUI_Workshop.h>
#include <ModuleBase_IWorkshop.h>
#include <ModuleBase_IViewer.h>
-
-#include <GeomValidators_Tools.h>
-
-#include <ModelAPI_Attribute.h>
-#include <ModelAPI_AttributeSelectionList.h>
+#include <ModuleBase_Tools.h>
#include <Config_PropManager.h>
#include <AIS_InteractiveContext.hxx>
+#include <AIS_InteractiveObject.hxx>
+#include <Prs3d_PointAspect.hxx>
-#define OPERATION_PARAMETER_COLOR "255, 255, 0"
+//#define DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop)
- : myWorkshop(theWorkshop)
+ : myWorkshop(theWorkshop), myFeature(FeaturePtr())
{
- Handle(PartSet_OperationPrs) myOperationPrs = new PartSet_OperationPrs(); /// AIS presentation for the feature of operation
+ initPresentation(ModuleBase_IModule::CustomizeArguments);
+ initPresentation(ModuleBase_IModule::CustomizeResults);
+ initPresentation(ModuleBase_IModule::CustomizeHighlightedObjects);
+
+ myIsActive[ModuleBase_IModule::CustomizeArguments] = false;
+ myIsActive[ModuleBase_IModule::CustomizeResults] = false;
+ myIsActive[ModuleBase_IModule::CustomizeHighlightedObjects] = false;
}
-void PartSet_CustomPrs::setCustomized(const FeaturePtr& theFeature)
+bool PartSet_CustomPrs::isActive(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag)
{
+ return myIsActive[theFlag];
+}
- myOperationPrs->setFeature(theFeature);
- /* QMap<ResultPtr, QList<GeomShapePtr> > aNewCustomized;
-
- QList<GeomShapePtr> aShapeList;
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
- if (aResult.get()) {
- aNewCustomized[aResult] = aShapeList;
+bool PartSet_CustomPrs::activate(const FeaturePtr& theFeature,
+ const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
+ const bool theUpdateViewer)
+{
+#ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
+ return false;
+#endif
+
+ myIsActive[theFlag] = true;
+ myFeature = theFeature;
+
+ bool isModified = false;
+ if (theFeature.get()) {
+ displayPresentation(ModuleBase_IModule::CustomizeArguments, theUpdateViewer);
+ displayPresentation(ModuleBase_IModule::CustomizeResults, theUpdateViewer);
+ displayPresentation(ModuleBase_IModule::CustomizeHighlightedObjects, theUpdateViewer);
+ isModified = true;
}
- 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;
- }
- }
- }
- }
- }
+ return isModified;
+}
+
+bool PartSet_CustomPrs::deactivate(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
+ const bool theUpdateViewer)
+{
+ myIsActive[theFlag] = false;
+ bool isModified = false;
+
+ erasePresentation(ModuleBase_IModule::CustomizeArguments, theUpdateViewer);
+ erasePresentation(ModuleBase_IModule::CustomizeResults, theUpdateViewer);
+ erasePresentation(ModuleBase_IModule::CustomizeHighlightedObjects, theUpdateViewer);
+ isModified = true;
+
+ return isModified;
+}
+
+bool PartSet_CustomPrs::displayPresentation(
+ const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
+ const bool theUpdateViewer)
+{
+ bool isModified = false;
+
+ // update the AIS objects content
+ Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(theFlag);
+ // do nothing if the feature can not be displayed [is moved from presentation, to be checked]
+ if (!myFeature.get())
+ return isModified;
+
+ switch (theFlag) {
+ case ModuleBase_IModule::CustomizeArguments:
+ PartSet_OperationPrs::getFeatureShapes(myFeature, myWorkshop, anOperationPrs->featureShapes());
+ break;
+ case ModuleBase_IModule::CustomizeResults:
+ PartSet_OperationPrs::getResultShapes(myFeature, myWorkshop, anOperationPrs->featureShapes());
+ break;
+ case ModuleBase_IModule::CustomizeHighlightedObjects:
+ PartSet_OperationPrs::getHighlightedShapes(myWorkshop, anOperationPrs->featureShapes());
+ break;
+ default:
+ return isModified;
}
- bool isDone = false;
- XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
- XGUI_Workshop* aWorkshop = aConnector->workshop();
- XGUI_Displayer* aDisplayer = aWorkshop->displayer();
+ // redisplay AIS objects
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;
+ if (!aContext.IsNull() && !aContext->IsDisplayed(anOperationPrs)) {
+ // when the feature can not be visualized in the module, the operation preview should not
+ // be visualized also
+ if (anOperationPrs->hasShapes() && myWorkshop->module()->canDisplayObject(myFeature)) {
+ // set color here because it can be changed in preferences
+ Quantity_Color aShapeColor = getShapeColor(theFlag);
+ anOperationPrs->setShapeColor(aShapeColor);
+
+ PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
+ XGUI_Workshop* aWorkshop = workshop();
+ aWorkshop->displayer()->displayAIS(myPresentations[theFlag], false/*load object in selection*/,
+ theUpdateViewer);
+ aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId());
+ isModified = true;
+ }
}
-
- 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);
+ else {
+ // when the feature can not be visualized in the module, the operation preview should not
+ // be visualized also
+ if (!anOperationPrs->hasShapes() || !myWorkshop->module()->canDisplayObject(myFeature)) {
+ erasePresentation(theFlag, theUpdateViewer);
+ isModified = true;
+ }
+ else {
+ anOperationPrs->Redisplay();
+ isModified = true;
+ if (theUpdateViewer)
+ workshop()->displayer()->updateViewer();
}
- isDone = aDisplayer->customizeObject(aResult);
}
+ return isModified;
+}
- // 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;
+void PartSet_CustomPrs::erasePresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
+ const bool theUpdateViewer)
+{
+ XGUI_Workshop* aWorkshop = workshop();
+ aWorkshop->displayer()->eraseAIS(myPresentations[theFlag], theUpdateViewer);
+}
+
+void PartSet_CustomPrs::clearPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag)
+{
+ Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(theFlag);
+ if (!anOperationPrs.IsNull())
+ anOperationPrs.Nullify();
+}
+
+Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation(
+ const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag)
+{
+ Handle(PartSet_OperationPrs) aPresentation;
+
+ if (myPresentations.contains(theFlag)) {
+ AISObjectPtr anOperationPrs = myPresentations[theFlag];
+ if (!anOperationPrs.get())
+ initPresentation(theFlag);
+ Handle(AIS_InteractiveObject) anAISIO = anOperationPrs->impl<Handle(AIS_InteractiveObject)>();
+ aPresentation = Handle(PartSet_OperationPrs)::DownCast(anAISIO);
}
- if (isDone)
- aDisplayer->updateViewer();*/
+ return aPresentation;
}
-/*#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 PartSet_CustomPrs::redisplay(const ObjectPtr& theObject,
+ const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
+ const bool theUpdateViewer)
{
- 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*+/
+#ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
+ return false;
+#endif
+ return displayPresentation(theFlag, theUpdateViewer);
+}
+
+void PartSet_CustomPrs::clearPrs()
+{
+ clearPresentation(ModuleBase_IModule::CustomizeArguments);
+ clearPresentation(ModuleBase_IModule::CustomizeResults);
+ clearPresentation(ModuleBase_IModule::CustomizeHighlightedObjects);
+}
+
+void PartSet_CustomPrs::initPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag)
+{
+ AISObjectPtr anOperationPrs = AISObjectPtr(new GeomAPI_AISObject());
+ Handle(PartSet_OperationPrs) anAISPrs = new PartSet_OperationPrs(myWorkshop);
+ anOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
+ if (theFlag == ModuleBase_IModule::CustomizeArguments ||
+ theFlag == ModuleBase_IModule::CustomizeResults) {
+ anOperationPrs->setPointMarker(5, 2.);
+ anOperationPrs->setWidth(1);
}
- /*
- 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();
+ else if (theFlag == ModuleBase_IModule::CustomizeHighlightedObjects)
+ anAISPrs->useAISWidth();
+
+ if (anOperationPrs.get())
+ myPresentations[theFlag] = anOperationPrs;
+}
+
+Quantity_Color PartSet_CustomPrs::getShapeColor(
+ const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag)
+{
+ Quantity_Color aColor;
+ switch(theFlag) {
+ case ModuleBase_IModule::CustomizeArguments:
+ aColor = ModuleBase_Tools::color("Visualization", "operation_parameter_color",
+ OPERATION_PARAMETER_COLOR());
+ break;
+ case ModuleBase_IModule::CustomizeResults:
+ aColor = ModuleBase_Tools::color("Visualization", "operation_result_color",
+ OPERATION_RESULT_COLOR());
+ break;
+ case ModuleBase_IModule::CustomizeHighlightedObjects:
+ aColor = ModuleBase_Tools::color("Visualization", "operation_highlight_color",
+ OPERATION_HIGHLIGHT_COLOR());
+ break;
+ default:
+ break;
}
- return !aColor.empty() && thePrs->setColor(aColor[0], aColor[1], aColor[2]);*/
- return isDone;
+ return aColor;
+}
+
+XGUI_Workshop* PartSet_CustomPrs::workshop() const
+{
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
+ return aConnector->workshop();
}