#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_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())
{
- myOperationPrs = AISObjectPtr(new GeomAPI_AISObject());
- myOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(new PartSet_OperationPrs(theWorkshop)));
+ initPresentation(ModuleBase_IModule::CustomizeArguments);
+ initPresentation(ModuleBase_IModule::CustomizeResults);
+ initPresentation(ModuleBase_IModule::CustomizeHighlightedObjects);
- std::vector<int> aColor = Config_PropManager::color("Visualization", "operation_parameter_color",
- OPERATION_PARAMETER_COLOR);
- myOperationPrs->setColor(aColor[0], aColor[1], aColor[2]);
+ myIsActive[ModuleBase_IModule::CustomizeArguments] = false;
+ myIsActive[ModuleBase_IModule::CustomizeResults] = false;
+ myIsActive[ModuleBase_IModule::CustomizeHighlightedObjects] = false;
+}
- myOperationPrs->setPointMarker(5, 2.);
- myOperationPrs->setWidth(1);
+bool PartSet_CustomPrs::isActive(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag)
+{
+ return myIsActive[theFlag];
}
-bool PartSet_CustomPrs::isActive() const
+bool PartSet_CustomPrs::activate(const FeaturePtr& theFeature,
+ const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
+ const bool theUpdateViewer)
{
- Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
- Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+#ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
+ return false;
+#endif
+
+ myIsActive[theFlag] = true;
+ myFeature = theFeature;
- return aContext->IsDisplayed(anOperationPrs);
+ bool isModified = false;
+ if (theFeature.get()) {
+ displayPresentation(ModuleBase_IModule::CustomizeArguments, theUpdateViewer);
+ displayPresentation(ModuleBase_IModule::CustomizeResults, theUpdateViewer);
+ displayPresentation(ModuleBase_IModule::CustomizeHighlightedObjects, theUpdateViewer);
+ isModified = true;
+ }
+ return isModified;
}
-void PartSet_CustomPrs::activate(const FeaturePtr& theFeature)
+bool PartSet_CustomPrs::deactivate(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
+ const bool theUpdateViewer)
{
- Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
+ myIsActive[theFlag] = false;
+ bool isModified = false;
- if (anOperationPrs->canActivate(theFeature)) {
- anOperationPrs->setFeature(theFeature);
- if (theFeature.get())
- displayPresentation();
- }
+ erasePresentation(ModuleBase_IModule::CustomizeArguments, theUpdateViewer);
+ erasePresentation(ModuleBase_IModule::CustomizeResults, theUpdateViewer);
+ erasePresentation(ModuleBase_IModule::CustomizeHighlightedObjects, theUpdateViewer);
+ isModified = true;
+
+ return isModified;
}
-void PartSet_CustomPrs::deactivate()
+bool PartSet_CustomPrs::displayPresentation(
+ const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
+ const bool theUpdateViewer)
{
- Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
- anOperationPrs->setFeature(FeaturePtr());
+ 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;
+ }
- erasePresentation();
+ // redisplay AIS objects
+ Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+ 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;
+ }
+ }
+ 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();
+ }
+ }
+ return isModified;
}
+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::displayPresentation()
+void PartSet_CustomPrs::clearPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag)
{
- Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
+ Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(theFlag);
+ if (!anOperationPrs.IsNull())
+ anOperationPrs.Nullify();
+}
- Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
- if (!aContext->IsDisplayed(anOperationPrs)) {
- PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
- aContext->Display(anOperationPrs);
- aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId());
+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);
}
- else
- anOperationPrs->Redisplay();
+ return aPresentation;
}
-void PartSet_CustomPrs::erasePresentation()
+bool PartSet_CustomPrs::redisplay(const ObjectPtr& theObject,
+ const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
+ const bool theUpdateViewer)
{
- Handle(AIS_InteractiveObject) anOperationPrs = myOperationPrs->impl<Handle(AIS_InteractiveObject)>();
- Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
- if (aContext->IsDisplayed(anOperationPrs))
- aContext->Remove(anOperationPrs);
+#ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
+ return false;
+#endif
+ return displayPresentation(theFlag, theUpdateViewer);
}
-Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation() const
+void PartSet_CustomPrs::clearPrs()
{
- Handle(AIS_InteractiveObject) anAISIO = myOperationPrs->impl<Handle(AIS_InteractiveObject)>();
- return Handle(PartSet_OperationPrs)::DownCast(anAISIO);
+ clearPresentation(ModuleBase_IModule::CustomizeArguments);
+ clearPresentation(ModuleBase_IModule::CustomizeResults);
+ clearPresentation(ModuleBase_IModule::CustomizeHighlightedObjects);
}
-bool PartSet_CustomPrs::customize(const ObjectPtr& theObject)
+void PartSet_CustomPrs::initPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag)
{
- // 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);
+ 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);
+ }
+ else if (theFlag == ModuleBase_IModule::CustomizeHighlightedObjects)
+ anAISPrs->useAISWidth();
- anOperationPrs->updateShapes();
- aChanged = aChanged || anOperationPrs->dependOn(theObject);
+ if (anOperationPrs.get())
+ myPresentations[theFlag] = anOperationPrs;
+}
- //if (aChanged)
- anOperationPrs->Redisplay();
+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 false;
+ return aColor;
}
-bool PartSet_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
- std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
+XGUI_Workshop* PartSet_CustomPrs::workshop() const
{
- return false;
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
+ return aConnector->workshop();
}