#include <ModuleBase_Tools.h>
#include <Config_PropManager.h>
+#include <Events_Loop.h>
+#include <ModelAPI_Events.h>
#include <AIS_InteractiveContext.hxx>
#include <AIS_InteractiveObject.hxx>
//#define DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop)
- : myWorkshop(theWorkshop), myFeature(FeaturePtr())
+ : myWorkshop(theWorkshop), myFeature(FeaturePtr()), myPresentationIsEmpty(false)
{
+ Events_Loop* aLoop = Events_Loop::loop();
+ aLoop->registerListener(this, Events_Loop::eventByName(EVENT_EMPTY_OPERATION_PRESENTATION));
+
initPresentation(ModuleBase_IModule::CustomizeArguments);
initPresentation(ModuleBase_IModule::CustomizeResults);
initPresentation(ModuleBase_IModule::CustomizeHighlightedObjects);
return isModified;
}
+ myPresentationIsEmpty = false;
// redisplay AIS objects
+ bool aRedisplayed = false;
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
PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
XGUI_Workshop* aWorkshop = workshop();
- aWorkshop->displayer()->displayAIS(myPresentations[theFlag], false/*load object in selection*/,
- theUpdateViewer);
+ aRedisplayed = aWorkshop->displayer()->displayAIS(myPresentations[theFlag],
+ false/*load object in selection*/, false);
aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId());
isModified = true;
}
// 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);
+ aRedisplayed = erasePresentation(theFlag, false);
isModified = true;
}
else {
anOperationPrs->Redisplay();
isModified = true;
- if (theUpdateViewer)
- workshop()->displayer()->updateViewer();
+ aRedisplayed = true;
}
}
+ if (myPresentationIsEmpty) {
+ aRedisplayed = erasePresentation(theFlag, false);
+ }
+ if (aRedisplayed && theUpdateViewer)
+ workshop()->displayer()->updateViewer();
+
return isModified;
}
-void PartSet_CustomPrs::erasePresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
+bool PartSet_CustomPrs::erasePresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
const bool theUpdateViewer)
{
+ bool isErased = false;
XGUI_Workshop* aWorkshop = workshop();
if (myPresentations.contains(theFlag))
- aWorkshop->displayer()->eraseAIS(myPresentations[theFlag], theUpdateViewer);
+ isErased = aWorkshop->displayer()->eraseAIS(myPresentations[theFlag], theUpdateViewer);
+ return isErased;
}
void PartSet_CustomPrs::clearPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag)
clearPresentation(ModuleBase_IModule::CustomizeHighlightedObjects);
}
+void PartSet_CustomPrs::processEvent(const std::shared_ptr<Events_Message>& theMessage)
+{
+ if (theMessage->eventID() == Events_Loop::eventByName(EVENT_EMPTY_OPERATION_PRESENTATION))
+ myPresentationIsEmpty = true; /// store state to analize it after display/erase is finished
+}
+
void PartSet_CustomPrs::initPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag)
{
AISObjectPtr anOperationPrs = AISObjectPtr(new GeomAPI_AISObject());
#include <ModelAPI_Result.h>
#include <ModelAPI_Feature.h>
+#include <Events_Listener.h>
+
#include <GeomAPI_ICustomPrs.h>
#include <GeomAPI_AISObject.h>
#include <GeomAPI_Shape.h>
* This is the module custom presentation, which manage an AIS presentation, that can be filled
* by a feature and visualized in the viewer additionally to usual workshop objects.
*/
-class PartSet_CustomPrs
+class PartSet_CustomPrs : public Events_Listener
{
public:
/// Returns yellow color
/// it caused erroneus case because the presentation has linkage to the previous context.
void clearPrs();
+ //! Redefinition of Events_Listener method to listen a moment that the presentation becomes empty
+ virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
+
private:
/// Creates the AIS operation presentation
/// \param theFlag an object AIS presentation type
/// Erases the internal presentation from the viewer of workshop
/// \param theFlag an object AIS presentation type
/// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
- void erasePresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
+ /// \param returns whether the presentation is erased
+ bool erasePresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
const bool theUpdateViewer);
/// Nullify the operation presentation. For example, it can be useful when the viewer/context
Quantity_Color getShapeColor(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
private:
+ bool myPresentationIsEmpty; /// Boolean state about empty presentation
FeaturePtr myFeature; /// Reference to a feature object
ModuleBase_IWorkshop* myWorkshop; /// current workshop
/// map of presentation type to AIS object