return new ModuleBase_OperationFeature(theFeatureId.c_str(), this);
}
+bool ModuleBase_IModule::customizeObject(ObjectPtr theObject, const bool theUpdateViewer)
+{
+ return false;
+}
+
ModuleBase_Operation* ModuleBase_IModule::createOperation(const std::string& theFeatureId)
{
ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
* 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
+ * \param theUpdateViewer the parameter whether the viewer should be update immediatelly\r
+ * \returns true if the object is modified\r
*/\r
- virtual void customizeObject(ObjectPtr theObject) {}\r
+ virtual bool customizeObject(ObjectPtr theObject, const bool theUpdateViewer);\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
return aContext->IsDisplayed(anOperationPrs);
}
-void PartSet_CustomPrs::activate(const FeaturePtr& theFeature)
+bool PartSet_CustomPrs::activate(const FeaturePtr& theFeature, const bool theUpdateViewer)
{
+ bool isModified = false;
Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
if (anOperationPrs->canActivate(theFeature)) {
anOperationPrs->setFeature(theFeature);
- if (theFeature.get())
- displayPresentation();
+ if (theFeature.get()) {
+ displayPresentation(theUpdateViewer);
+ isModified = true;
+ }
}
+ return isModified;
}
-void PartSet_CustomPrs::deactivate()
+bool PartSet_CustomPrs::deactivate(const bool theUpdateViewer)
{
+ bool isModified = false;
+
Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
anOperationPrs->setFeature(FeaturePtr());
- erasePresentation();
+ Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+ if (aContext->IsDisplayed(anOperationPrs)) {
+ erasePresentation(theUpdateViewer);
+ isModified = true;
+ }
+
+ return isModified;
}
-void PartSet_CustomPrs::displayPresentation()
+void PartSet_CustomPrs::displayPresentation(const bool theUpdateViewer)
{
Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
XGUI_Workshop* aWorkshop = workshop();
- aWorkshop->displayer()->displayAIS(myOperationPrs, false/*load object in selection*/, true);
+ aWorkshop->displayer()->displayAIS(myOperationPrs, false/*load object in selection*/, theUpdateViewer);
aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId());
}
else {
anOperationPrs->Redisplay();
- workshop()->displayer()->updateViewer();
+ if (theUpdateViewer)
+ workshop()->displayer()->updateViewer();
}
}
-void PartSet_CustomPrs::erasePresentation()
+void PartSet_CustomPrs::erasePresentation(const bool theUpdateViewer)
{
XGUI_Workshop* aWorkshop = workshop();
- aWorkshop->displayer()->eraseAIS(myOperationPrs, true);
+ aWorkshop->displayer()->eraseAIS(myOperationPrs, theUpdateViewer);
}
Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation()
return Handle(PartSet_OperationPrs)::DownCast(anAISIO);
}
-void PartSet_CustomPrs::customize(const ObjectPtr& theObject)
+bool PartSet_CustomPrs::redisplay(const ObjectPtr& theObject, const bool theUpdateViewer)
{
+ bool isModified = false;
// 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();
//aChanged = aChanged || anOperationPrs->dependOn(theObject);
//if (aChanged)
anOperationPrs->Redisplay();
+ isModified = true;
+ if (theUpdateViewer)
+ workshop()->displayer()->updateViewer();
}
+ return isModified;
}
void PartSet_CustomPrs::clearPrs()
class XGUI_Workshop;
/**
-* Interface of a class which can provide specific customization of
-* object presentation
+ * 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
{
/// Returns true if the presentation is active
bool isActive();
- /// Initializes the presentation by the parameter object
- void activate(const FeaturePtr& theObject);
-
- void deactivate();
-
- /// Modifies the given presentation in the custom way.
- void customize(const ObjectPtr& theObject);
-
+ /// Initializes the operation presentation by the parameter object and display the presentation
+ /// \param theObject an operation feature source to fill the presentation
+ /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
+ /// \returns true if the presentation is displayed
+ bool activate(const FeaturePtr& theObject, const bool theUpdateViewer);
+
+ /// Initializes the operation presentation by empty object and erase the presentation
+ /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
+ /// \returns true if the presentation has been displayed and now it is erased
+ bool deactivate(const bool theUpdateViewer);
+
+ /// If the presentation is active[displayed], the shapes of the presentation is recomputed
+ /// and the presentation is redisplayed.
+ /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
+ /// \returns true if the presentation is redisplayed
+ bool redisplay(const ObjectPtr& theObject, const bool theUpdateViewer);
+
+ /// Nullify the operation presentation. For example, it can be useful when the viewer/context
+ /// is closed. If this is not performed and the presentation is assigned in another context,
+ /// it caused erroneus case because the presentation has linkage to the previous context.
void clearPrs();
+private:
+ /// Creates the AIS operation presentation
void initPrs();
-private:
/// Returns the AIS presentation
Handle(PartSet_OperationPrs) getPresentation();
XGUI_Workshop* workshop() const;
/// Displays the internal presentation in the viewer of workshop
- void displayPresentation();
+ /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
+ void displayPresentation(const bool theUpdateViewer);
+
/// Erases the internal presentation from the viewer of workshop
- void erasePresentation();
+ /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
+ void erasePresentation(const bool theUpdateViewer);
+
/// Sets color, point size and width of the presentation
- void customizePresentation();
+ /// \param theUpdateViewer the parameter whether the viewer should be update immediatelly
+ void customizePresentation(const bool theUpdateViewer);
private:
ModuleBase_IWorkshop* myWorkshop; /// current workshop
ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
if (aFOperation)
- myCustomPrs->activate(aFOperation->feature());
+ myCustomPrs->activate(aFOperation->feature(), true);
}
void PartSet_Module::onOperationResumed(ModuleBase_Operation* theOperation)
ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
if (aFOperation)
- myCustomPrs->activate(aFOperation->feature());
+ myCustomPrs->activate(aFOperation->feature(), true);
}
void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
{
- myCustomPrs->deactivate();
+ bool isModified = myCustomPrs->deactivate(false);
if (PartSet_SketcherMgr::isSketchOperation(theOperation)) {
mySketchMgr->stopSketch(theOperation);
else if (PartSet_SketcherMgr::isNestedSketchOperation(theOperation)) {
mySketchMgr->stopNestedSketch(theOperation);
}
+
+ if (isModified) {
+ XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
+ XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
+ aDisplayer->updateViewer();
+ }
}
ModuleBase_Operation* PartSet_Module::currentOperation() const
void PartSet_Module::onBeforeObjectErase(ObjectPtr theObject, AISObjectPtr theAIS)
{
+ // this is obsolete
// it should be recomputed in order to disappear in the viewer if the corresponded object
// is erased
- if (myCustomPrs->isActive())
- myCustomPrs->customize(theObject);
+ //if (myCustomPrs->isActive())
+ // myCustomPrs->redisplay(theObject, false);
}
void PartSet_Module::onViewTransformed(int theTrsfType)
aDisplayer->updateViewer();
}
-void PartSet_Module::customizeObject(ObjectPtr theObject)
+bool PartSet_Module::customizeObject(ObjectPtr theObject, const bool theUpdateViewer)
{
+ bool isRedisplayed = false;
if (myCustomPrs->isActive())
- myCustomPrs->customize(theObject);
+ isRedisplayed = myCustomPrs->redisplay(theObject, theUpdateViewer);
+
+ return isRedisplayed;
}
void PartSet_Module::customizeObjectBrowser(QWidget* theObjectBrowser)
* 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
+ * \param theUpdateViewer the parameter whether the viewer should be update immediatelly
+ * \returns true if the object is modified
*/
- virtual void customizeObject(ObjectPtr theObject);
+ virtual bool customizeObject(ObjectPtr theObject, const bool theUpdateViewer);
/// This method is called on object browser creation for customisation of module specific features
/// \param theObjectBrowser a pinter on Object Browser widget
//#define DEBUG_FEATURE_CREATED
//#define DEBUG_FEATURE_REDISPLAY
+//#define DEBUG_FEATURE_UPDATED
//#define DEBUG_RESULT_COMPSOLID
XGUI_WorkshopListener::XGUI_WorkshopListener(ModuleBase_IWorkshop* theWorkshop)
void XGUI_WorkshopListener::onFeatureUpdatedMsg(
const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
{
+#ifdef DEBUG_FEATURE_UPDATED
+ std::set<ObjectPtr> aObjects = theMsg->objects();
+ std::set<ObjectPtr>::const_iterator aIt;
+ QStringList anInfo;
+ for (aIt = aObjects.begin(); aIt != aObjects.end(); ++aIt) {
+ anInfo.append(ModuleBase_Tools::objectInfo((*aIt)));
+ }
+ QString anInfoStr = anInfo.join(";\t");
+ qDebug(QString("onFeatureUpdatedMsg: %1, %2").arg(aObjects.size()).arg(anInfoStr).toStdString().c_str());
+#endif
+ bool isModified = false;
std::set<ObjectPtr> aFeatures = theMsg->objects();
XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
if (anOperationMgr->hasOperation()) {
break;
}
}
- myWorkshop->module()->customizeObject(aCurrentFeature);
+ isModified = myWorkshop->module()->customizeObject(aCurrentFeature, false);
}
}
anOperationMgr->onValidateOperation();
//if (myObjectBrowser)
// myObjectBrowser->processEvent(theMsg);
+ if (isModified)
+ workshop()->displayer()->updateViewer();
}
//******************************************************