static Events_ID EVENT_LOAD = Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED);
ModelAPI_EventCreator::get()->sendUpdated(ObjectPtr(), EVENT_LOAD);
Events_Loop::loop()->flush(EVENT_LOAD);
+ // If the plugin has an ability to process GUI events, register it
+ Events_Listener* aListener = dynamic_cast<Events_Listener*>(thePlugin);
+ if (aListener) {
+ Events_Loop* aLoop = Events_Loop::loop();
+ static Events_ID aStateRequestEventId =
+ Events_Loop::loop()->eventByName(EVENT_FEATURE_STATE_REQUEST);
+ aLoop->registerListener(aListener, aStateRequestEventId);
+ }
}
ModelAPI_ValidatorsFactory* Model_Session::validators()
}
}
}
- addDefaultValidators(theResult);
+ addDefaultValidators(theResult, theArguments);
}
void Model_ValidatorsFactory::validators(const std::string& theFeatureID,
return NULL;
}
-void Model_ValidatorsFactory::addDefaultValidators(std::list<ModelAPI_Validator*>& theValidators) const
+void Model_ValidatorsFactory::addDefaultValidators(std::list<ModelAPI_Validator*>& theValidators,
+ std::list<std::list<std::string> >& theArguments) const
{
const static std::string kDefaultId = "Model_FeatureValidator";
std::map<std::string, ModelAPI_Validator*>::const_iterator it = myIDs.find(kDefaultId);
if(it == myIDs.end())
return;
theValidators.push_back(it->second);
+ theArguments.push_back(std::list<std::string>());
}
bool Model_ValidatorsFactory::validate(const std::shared_ptr<ModelAPI_Feature>& theFeature) const
virtual bool isConcealed(std::string theFeature, std::string theAttribute);
protected:
- void addDefaultValidators(std::list<ModelAPI_Validator*>& theValidators) const;
+ void addDefaultValidators(std::list<ModelAPI_Validator*>& theValidators,
+ std::list<std::list<std::string> >& theArguments) const;
/// Get instance from Session
Model_ValidatorsFactory();
}
+ModelAPI_FeatureStateMessage::ModelAPI_FeatureStateMessage(const Events_ID theID,
+ const void* theSender)
+ : Events_Message(theID, theSender)
+{
+ myCurrentFeature = std::shared_ptr<ModelAPI_Feature>();
+}
+
+ModelAPI_FeatureStateMessage::~ModelAPI_FeatureStateMessage()
+{
+
+}
+
+std::shared_ptr<ModelAPI_Feature> ModelAPI_FeatureStateMessage::feature() const
+{
+ return myCurrentFeature;
+}
+
+void ModelAPI_FeatureStateMessage::setFeature(std::shared_ptr<ModelAPI_Feature>& theFeature)
+{
+ myCurrentFeature = theFeature;
+}
+
+bool ModelAPI_FeatureStateMessage::hasState(const std::string& theKey) const
+{
+ return myFeatureState.find(theKey) != myFeatureState.end();
+}
+
+bool ModelAPI_FeatureStateMessage::state(const std::string& theFeatureId, bool theDefault) const
+{
+ if(hasState(theFeatureId)) {
+ return myFeatureState.at(theFeatureId);
+ }
+ return theDefault;
+}
+
+void ModelAPI_FeatureStateMessage::setState(const std::string& theFeatureId, bool theValue)
+{
+ myFeatureState[theFeatureId] = theValue;
+}
+
+std::list<std::string> ModelAPI_FeatureStateMessage::features() const
+{
+ std::list<std::string> result;
+ std::map<std::string, bool>::const_iterator it = myFeatureState.begin();
+ for( ; it != myFeatureState.end(); ++it) {
+ result.push_back(it->first);
+ }
+ return result;
+}
+
#include <ModelAPI.h>
#include <ModelAPI_Object.h>
+#include <ModelAPI_Feature.h>
#include <Events_MessageGroup.h>
#include <memory>
#include <string>
#include <set>
+#include <map>
class ModelAPI_Document;
/// Event ID that data of feature has to be shown (comes with ModelAPI_ObjectUpdatedMessage)
static const char * EVENT_OBJECT_TOHIDE = "ObjectHide";
+static const char * EVENT_FEATURE_STATE_REQUEST = "FeatureStateRequest";
+static const char * EVENT_FEATURE_STATE_RESPONSE = "FeatureStateResponse";
+
/// Message that feature was changed (used for Object Browser update): moved, updated and deleted
class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
{
static void set(const ModelAPI_EventCreator* theCreator);
};
+// TODO(sbh): Move this message into a separate package, like "GuiAPI"
+class ModelAPI_FeatureStateMessage : public Events_Message
+{
+ public:
+ MODELAPI_EXPORT ModelAPI_FeatureStateMessage(const Events_ID theID, const void* theSender = 0);
+ MODELAPI_EXPORT virtual ~ModelAPI_FeatureStateMessage();
+
+ // For request
+ MODELAPI_EXPORT std::shared_ptr<ModelAPI_Feature> feature() const;
+ MODELAPI_EXPORT void setFeature(std::shared_ptr<ModelAPI_Feature>& theFeature);
+ // For response
+ MODELAPI_EXPORT bool hasState(const std::string& theFeatureId) const;
+ MODELAPI_EXPORT bool state(const std::string& theFeatureId, bool theDefault = false) const;
+ MODELAPI_EXPORT void setState(const std::string& theFeatureId, bool theValue);
+ MODELAPI_EXPORT std::list<std::string> features() const;
+
+ private:
+ // For Request
+ std::shared_ptr<ModelAPI_Feature> myCurrentFeature;
+ // For response
+ std::map<std::string, bool> myFeatureState;
+};
+
#endif
ModelAPI_Plugin()
{
}
- ;
};
#endif
return aFactory->validate(myFeature);
}
-bool ModuleBase_Operation::isNestedOperationsEnabled() const
-{
- return true;
-}
-
//void ModuleBase_Operation::storeCustomValue()
//{
// if (!myFeature) {
bool ModuleBase_Operation::isGranted(QString theId) const
{
return myNestedFeatures.contains(theId);
-}
\ No newline at end of file
+}
*/
virtual bool isValid() const;
- /// Returns whether the nested operations are enabled.
- /// The state can depend on the operation current state.
- /// \return enabled state
- virtual bool isNestedOperationsEnabled() const;
-
/// Sets the operation feature
void setFeature(FeaturePtr theFeature);
#include <ModelAPI_Validator.h>
+#include <list>
+#include <string>
+
class ModuleBase_SelectionValidator : public ModelAPI_Validator
{
public:
virtual bool isValid(const ModuleBase_ISelection* theSelection) const = 0;
+ virtual bool isValid(const ModuleBase_ISelection* theSelection,
+ const std::list<std::string>& theArguments) const
+ {
+ return isValid(theSelection);
+ }
};
#endif
PartSet_WidgetPoint2d.h
PartSet_WidgetPoint2dDistance.h
PartSet_WidgetShapeSelector.h
- PartSet_OperationSketch.h
PartSet_Filters.h
)
PartSet_WidgetPoint2d.cpp
PartSet_WidgetPoint2dDistance.cpp
PartSet_WidgetShapeSelector.cpp
- PartSet_OperationSketch.cpp
PartSet_Filters.cpp
)
// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
#include "PartSet_Module.h"
-#include <PartSet_OperationSketch.h>
#include <PartSet_WidgetSketchLabel.h>
#include <PartSet_Validators.h>
#include <PartSet_Tools.h>
aFactory->registerValidator("PartSet_PerpendicularValidator", new PartSet_PerpendicularValidator);
aFactory->registerValidator("PartSet_ParallelValidator", new PartSet_ParallelValidator);
aFactory->registerValidator("PartSet_RadiusValidator", new PartSet_RadiusValidator);
+ aFactory->registerValidator("PartSet_RigidValidator", new PartSet_RigidValidator);
aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator);
}
}
}
-/// Returns new instance of operation object (used in createOperation for customization)
-ModuleBase_Operation* PartSet_Module::getNewOperation(const std::string& theFeatureId)
-{
- if (theFeatureId == PartSet_OperationSketch::Type()) {
- return new PartSet_OperationSketch(theFeatureId.c_str(), this);
- }
- return ModuleBase_IModule::getNewOperation(theFeatureId);
-}
-
-
void PartSet_Module::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
{
myWorkshop->viewer()->enableSelection(true);
void launchEditing();
protected:
- /// Returns new instance of operation object (used in createOperation for customization)
- virtual ModuleBase_Operation* getNewOperation(const std::string& theFeatureId);
-
/// Register validators for this module
virtual void registerValidators();
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: PartSet_OperationSketch.h
-// Created: 20 Apr 2014
-// Author: Natalia ERMOLAEVA
-
-#include <PartSet_OperationSketch.h>
-#include <PartSet_Tools.h>
-
-#include <SketchPlugin_Sketch.h>
-#include <SketchPlugin_ConstraintLength.h>
-
-#include <ModelAPI_Data.h>
-#include <ModelAPI_AttributeDouble.h>
-#include <ModelAPI_AttributeRefList.h>
-#include <ModelAPI_Events.h>
-
-#include <GeomAlgoAPI_FaceBuilder.h>
-#include <GeomDataAPI_Point.h>
-#include <GeomDataAPI_Dir.h>
-#include <GeomAPI_XYZ.h>
-
-#include <ModuleBase_ViewerPrs.h>
-#include <ModuleBase_ISelection.h>
-#include <ModuleBase_IViewer.h>
-#include <Events_Loop.h>
-
-#ifdef _DEBUG
-#include <QDebug>
-#endif
-
-#include <QMouseEvent>
-
-using namespace std;
-
-PartSet_OperationSketch::PartSet_OperationSketch(const QString& theId, QObject* theParent)
- : ModuleBase_Operation(theId, theParent)
-{
-}
-
-PartSet_OperationSketch::~PartSet_OperationSketch()
-{
-}
-
-bool PartSet_OperationSketch::isNestedOperationsEnabled() const
-{
- bool aHasSketchPlane = false;
- if (feature()) {
- std::shared_ptr<ModelAPI_Data> aData = feature()->data();
- AttributeDoublePtr anAttr;
- std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- aData->attribute(SketchPlugin_Sketch::NORM_ID()));
- aHasSketchPlane = aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
- }
- return aHasSketchPlane;
-}
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: PartSet_OperationSketch.h
-// Created: 20 Apr 2014
-// Author: Natalia ERMOLAEVA
-
-#ifndef PartSet_OperationSketch_H
-#define PartSet_OperationSketch_H
-
-#include "PartSet.h"
-
-#include <ModuleBase_Operation.h>
-#include <SketchPlugin_Sketch.h>
-
-/*!
- \class PartSet_OperationSketch
- * \brief The operation for the sketch feature creation
- */
-class PARTSET_EXPORT PartSet_OperationSketch : public ModuleBase_Operation
-{
-Q_OBJECT
-
- public:
- /// Returns the operation type key
- static std::string Type()
- {
- return SketchPlugin_Sketch::ID();
- }
-
- /// Constructor
- /// \param theId the feature identifier
- /// \param theParent the operation parent
- PartSet_OperationSketch(const QString& theId, QObject* theParent);
- /// Destructor
- virtual ~PartSet_OperationSketch();
-
- /// Returns whether the nested operations are enabled.
- /// The state can depend on the operation current state.
- /// It returns true after the sketch plane is choosen.
- /// \return enabled state
- virtual bool isNestedOperationsEnabled() const;
-
-};
-
-#endif
#include <ModelAPI_AttributeReference.h>
#include <list>
+#ifdef _DEBUG
+#include <iostream>
+#endif
int shapesNbPoints(const ModuleBase_ISelection* theSelection)
{
bool PartSet_DistanceValidator::isValid(const ModuleBase_ISelection* theSelection) const
{
- int aCount = shapesNbPoints(theSelection);
+ int aCount = shapesNbPoints(theSelection) + shapesNbLines(theSelection);
return (aCount > 0) && (aCount < 3);
}
return (aCount > 0) && (aCount < 2);
}
-
+bool PartSet_RigidValidator::isValid(const ModuleBase_ISelection* theSelection) const
+{
+ int aCount = shapesNbLines(theSelection);
+ return (aCount > 0) && (aCount < 2);
+}
bool PartSet_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
const std::list<std::string>& theArguments,
{
// not implemented
return true;
-}
\ No newline at end of file
+}
PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
};
+//! A class to validate a selection for Perpendicular constraint operation
+class PartSet_RigidValidator : public ModuleBase_SelectionValidator
+{
+ public:
+ PARTSET_EXPORT virtual bool isValid(const ModuleBase_ISelection* theSelection) const;
+};
+
class PartSet_DifferentObjectsValidator : public ModelAPI_RefAttrValidator
{
public:
TARGET_LINK_LIBRARIES(PartSetPlugin ${PROJECT_LIBRARIES} ModelAPI)
INCLUDE_DIRECTORIES(
+ ../Events
../ModelAPI
../GeomAPI
)
#include "PartSetPlugin_Part.h"
#include "PartSetPlugin_Duplicate.h"
#include "PartSetPlugin_Remove.h"
+
+#include <Events_Loop.h>
+
#include <ModelAPI_Session.h>
#include <ModelAPI_Document.h>
+#ifdef _DEBUG
+#include <iostream>
+#endif
+
using namespace std;
// the only created instance of this plugin
// feature of such kind is not found
return FeaturePtr();
}
+
+void PartSetPlugin_Plugin::processEvent(const std::shared_ptr<Events_Message>& theMessage)
+{
+ const Events_ID kRequestEvent =
+ Events_Loop::loop()->eventByName(EVENT_FEATURE_STATE_REQUEST);
+ if (theMessage->eventID() == kRequestEvent) {
+ Events_Loop::loop()->send(getFeaturesState(), false);
+ } else if (theMessage.get()) {
+ #ifdef _DEBUG
+ std::cout << "PartSetPlugin_Plugin::processEvent: unhandled message caught: " << std::endl
+ << theMessage->eventID().eventText() << std::endl;
+ #endif
+ }
+}
+
+std::shared_ptr<ModelAPI_FeatureStateMessage> PartSetPlugin_Plugin::getFeaturesState()
+{
+ const Events_ID kResponseEvent =
+ Events_Loop::loop()->eventByName(EVENT_FEATURE_STATE_RESPONSE);
+ std::shared_ptr<ModelAPI_FeatureStateMessage> aMsg =
+ std::make_shared<ModelAPI_FeatureStateMessage>(kResponseEvent, this);
+ std::string aStdDocKind = ModelAPI_Session::get()->activeDocument()->kind();
+ bool aDocIsPart = (aStdDocKind == PartSetPlugin_Part::ID());
+ aMsg->setState(PartSetPlugin_Part::ID(), true);
+ aMsg->setState(PartSetPlugin_Duplicate::ID(), aDocIsPart);
+ aMsg->setState(PartSetPlugin_Remove::ID(), aDocIsPart);
+ return aMsg;
+}
#ifndef PartSetPlugin_Plugin_H_
#define PartSetPlugin_Plugin_H_
-#include "PartSetPlugin.h"
-#include "ModelAPI_Plugin.h"
-#include "ModelAPI_Feature.h"
+#include <PartSetPlugin.h>
+#include <ModelAPI_Plugin.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Events.h>
-class PARTSETPLUGIN_EXPORT PartSetPlugin_Plugin : public ModelAPI_Plugin
+#include <Events_Listener.h>
+
+#include <memory>
+
+class PARTSETPLUGIN_EXPORT PartSetPlugin_Plugin : public ModelAPI_Plugin,
+ public Events_Listener
{
public:
/// Creates the feature object of this plugin by the feature string ID
virtual FeaturePtr createFeature(std::string theFeatureID);
- public:
/// Is needed for python wrapping by swig
PartSetPlugin_Plugin();
+
+ //! Redefinition of Events_Listener method
+ virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
+ std::shared_ptr<ModelAPI_FeatureStateMessage> getFeaturesState();
};
#endif
INCLUDE_DIRECTORIES(
../Config
+ ../Events
../ModelAPI
../GeomAPI
../GeomAlgoAPI
// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-#include "SketchPlugin_Plugin.h"
-#include "SketchPlugin_Sketch.h"
-#include "SketchPlugin_Line.h"
-#include "SketchPlugin_Point.h"
-#include "SketchPlugin_Circle.h"
-#include "SketchPlugin_Arc.h"
-#include "SketchPlugin_ConstraintCoincidence.h"
-#include "SketchPlugin_ConstraintDistance.h"
-#include "SketchPlugin_ConstraintLength.h"
-#include "SketchPlugin_ConstraintParallel.h"
-#include "SketchPlugin_ConstraintPerpendicular.h"
-#include "SketchPlugin_ConstraintRadius.h"
-#include "SketchPlugin_ConstraintRigid.h"
-#include "SketchPlugin_Validators.h"
-#include "SketchPlugin_ResultValidators.h"
+#include <SketchPlugin_Plugin.h>
+#include <SketchPlugin_Sketch.h>
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Point.h>
+#include <SketchPlugin_Circle.h>
+#include <SketchPlugin_Arc.h>
+#include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_ConstraintDistance.h>
+#include <SketchPlugin_ConstraintLength.h>
+#include <SketchPlugin_ConstraintParallel.h>
+#include <SketchPlugin_ConstraintPerpendicular.h>
+#include <SketchPlugin_ConstraintRadius.h>
+#include <SketchPlugin_ConstraintRigid.h>
+#include <SketchPlugin_Validators.h>
+#include <SketchPlugin_ResultValidators.h>
+
+#include <Events_Loop.h>
+#include <GeomDataAPI_Dir.h>
+
#include <ModelAPI_Session.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Validator.h>
+#include <ModelAPI_Data.h>
#include <Config_PropManager.h>
+#include <memory>
+
+#ifdef _DEBUG
+#include <iostream>
+#endif
+
using namespace std;
// the only created instance of this plugin
// feature of such kind is not found
return FeaturePtr();
}
+
+void SketchPlugin_Plugin::processEvent(const std::shared_ptr<Events_Message>& theMessage)
+{
+ const Events_ID kRequestEvent =
+ Events_Loop::loop()->eventByName(EVENT_FEATURE_STATE_REQUEST);
+ if (theMessage->eventID() == kRequestEvent) {
+ std::shared_ptr<ModelAPI_FeatureStateMessage> aStateMessage =
+ std::dynamic_pointer_cast<ModelAPI_FeatureStateMessage>(theMessage);
+ Events_Loop::loop()->send(getFeaturesState(aStateMessage->feature()), false);
+ }
+}
+
+std::shared_ptr<ModelAPI_FeatureStateMessage> SketchPlugin_Plugin
+::getFeaturesState(const std::shared_ptr<ModelAPI_Feature>& theFeature) const
+{
+ const Events_ID kResponseEvent = Events_Loop::loop()->eventByName(EVENT_FEATURE_STATE_RESPONSE);
+ std::shared_ptr<ModelAPI_FeatureStateMessage> aMsg =
+ std::make_shared<ModelAPI_FeatureStateMessage>(kResponseEvent, this);
+
+ bool aHasSketchPlane = false;
+ std::shared_ptr<SketchPlugin_Sketch> aSketchFeature =
+ std::dynamic_pointer_cast<SketchPlugin_Sketch>(theFeature);
+ if (aSketchFeature.get()) {
+ std::shared_ptr<ModelAPI_Data> aData = aSketchFeature->data();
+ std::shared_ptr<GeomDataAPI_Dir> aNormal =
+ std::dynamic_pointer_cast<GeomDataAPI_Dir>(aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+ aHasSketchPlane = aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
+
+ aMsg->setState(SketchPlugin_Point::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_Line::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_Circle::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_Arc::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_ConstraintCoincidence::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_ConstraintDistance::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_ConstraintLength::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_ConstraintParallel::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_ConstraintPerpendicular::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_ConstraintRadius::ID(), aHasSketchPlane);
+ aMsg->setState(SketchPlugin_ConstraintRigid::ID(), aHasSketchPlane);
+ }
+ return aMsg;
+}
// Created: 31 Mar 2014
// Author: Mikhail PONIKAROV
-#ifndef SketchPlugin_Plugin_H_
-#define SketchPlugin_Plugin_H_
+#ifndef SKETCHPLUGIN_PLUGIN_H_
+#define SKETCHPLUGIN_PLUGIN_H_
-#include "SketchPlugin.h"
-#include "ModelAPI_Plugin.h"
-#include "ModelAPI_Feature.h"
+#include <SketchPlugin.h>
+#include <Events_Listener.h>
+#include <ModelAPI_Plugin.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Events.h>
-class SKETCHPLUGIN_EXPORT SketchPlugin_Plugin : public ModelAPI_Plugin
+class SKETCHPLUGIN_EXPORT SketchPlugin_Plugin : public ModelAPI_Plugin, public Events_Listener
{
public:
/// Creates the feature object of this plugin by the feature string ID
public:
/// Is needed for python wrapping by swig
SketchPlugin_Plugin();
+ //! Redefinition of Events_Listener method
+ virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
+ protected:
+ std::shared_ptr<ModelAPI_FeatureStateMessage> getFeaturesState(
+ const std::shared_ptr<ModelAPI_Feature>& theFeature) const;
};
#endif
</feature>
<!-- SketchConstraintRigid -->
<feature id="SketchConstraintRigid" title="Fixed" tooltip="Create constraint defining fixed object" icon=":icons/fixed.png">
- <shape_selector id="ConstraintEntityA" label="Object" tooltip="Select any object in the viewer"
+ <shape_selector id="ConstraintEntityA" label="Object" tooltip="Select any object in the viewer"
shape_types="edge vertex">
<validator id="SketchPlugin_ResultPoint"/>
<validator id="SketchPlugin_ResultLine"/>
<validator id="SketchPlugin_ResultArc"/>
</shape_selector>
+ <validator id="PartSet_RigidValidator"/>
</feature>
</group>
</workbench>
* XGUI_ActionsMgr.cpp
*/
-#include "XGUI_ActionsMgr.h"
-#include "XGUI_Workshop.h"
-#include "XGUI_OperationMgr.h"
-#include "XGUI_SalomeConnector.h"
-
#include <AppElements_Command.h>
-#include <ModelAPI_Session.h>
+#include <XGUI_ActionsMgr.h>
+#include <XGUI_Workshop.h>
+#include <XGUI_OperationMgr.h>
+#include <XGUI_SalomeConnector.h>
+#include <XGUI_Selection.h>
+#include <XGUI_SelectionMgr.h>
-#include <ModuleBase_Operation.h>
+#include <Events_Loop.h>
#include <Events_Error.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Events.h>
+#include <ModelAPI_Validator.h>
+#include <ModuleBase_Operation.h>
+#include <ModuleBase_SelectionValidator.h>
+
+
#include <QAction>
#ifdef _DEBUG
myShortcuts << QKeySequence::Redo;
myShortcuts << QKeySequence::Open;
myShortcuts << QKeySequence::Close;
+
+ //Initialize event listening
+ Events_Loop* aLoop = Events_Loop::loop();
+ static Events_ID aStateResponseEventId =
+ Events_Loop::loop()->eventByName(EVENT_FEATURE_STATE_RESPONSE);
+ aLoop->registerListener(this, aStateResponseEventId, NULL, true);
}
XGUI_ActionsMgr::~XGUI_ActionsMgr()
myNestedActions[theId] = theCommands;
}
+QStringList XGUI_ActionsMgr::nestedCommands(const QString& theId) const
+{
+ if (myNestedActions.contains(theId))
+ return myNestedActions[theId];
+ return QStringList();
+}
+
+bool XGUI_ActionsMgr::isNested(const QString& theId) const
+{
+ foreach(QString aId, myNestedActions.keys())
+ {
+ QStringList aList = myNestedActions[aId];
+ if (aList.contains(theId))
+ return true;
+ }
+ return false;
+}
+
void XGUI_ActionsMgr::update()
{
+ FeaturePtr anActiveFeature = FeaturePtr();
if (myOperationMgr->hasOperation()) {
ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
- FeaturePtr aFeature = anOperation->feature();
- if(aFeature) {
+ anActiveFeature = anOperation->feature();
+ if(anActiveFeature.get()) {
setAllEnabled(false);
- QString aFeatureId = QString::fromStdString(aFeature->getKind());
+ QString aFeatureId = QString::fromStdString(anActiveFeature->getKind());
setActionEnabled(aFeatureId, true);
- setNestedStackEnabled(anOperation);
}
+ setNestedStackEnabled(anOperation);
} else {
setAllEnabled(true);
setNestedCommandsEnabled(false);
}
+ // TODO(SBH): Get defaults state of actions from XML and remove the following method
updateByDocumentKind();
updateCheckState();
+ updateByPlugins(anActiveFeature);
}
-void XGUI_ActionsMgr::setAllEnabled(bool isEnabled)
+void XGUI_ActionsMgr::updateCheckState()
{
- foreach(QString eachAction, myActions.keys())
- {
- setActionEnabled(eachAction, isEnabled);
+ QString eachCommand = QString();
+ foreach(eachCommand, myActions.keys()) {
+ setActionChecked(eachCommand, false);
+ }
+ QStringList ltActiveCommands = myOperationMgr->operationList();
+ foreach(eachCommand, ltActiveCommands) {
+ setActionChecked(eachCommand, true);
}
}
-void XGUI_ActionsMgr::setNestedStackEnabled(ModuleBase_Operation* theOperation)
+void XGUI_ActionsMgr::updateOnViewSelection()
{
- if(!theOperation || !theOperation->feature())
+ XGUI_Selection* aSelection = myWorkshop->selector()->selection();
+ if (aSelection->getSelected().size() == 0 || !myOperationMgr->hasOperation())
return;
- FeaturePtr aFeature = theOperation->feature();
- QString aFeatureId = QString::fromStdString(aFeature->getKind());
- bool isNestedEnabled = theOperation->isNestedOperationsEnabled();
- setNestedCommandsEnabled(isNestedEnabled, aFeatureId);
+ ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
+ FeaturePtr anActiveFeature = anOperation->feature();
+ if(!anActiveFeature.get())
+ return;
+ QString aFeatureId = QString::fromStdString(anActiveFeature->getKind());
- setNestedStackEnabled(myOperationMgr->previousOperation(theOperation));
+ SessionPtr aMgr = ModelAPI_Session::get();
+ ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+ foreach(QString aId, nestedCommands(aFeatureId)) {
+ std::list<ModelAPI_Validator*> aValidators;
+ std::list<std::list<std::string> > anArguments;
+ if (!anArguments.empty()) {
+ std::list<std::string> firstArg = anArguments.front();
+ }
+ aFactory->validators(aId.toStdString(), aValidators, anArguments);
+ std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
+ std::list<std::list<std::string> >::iterator aValidatorArgs = anArguments.begin();
+ for (; aValidator != aValidators.end(); aValidator++, aValidatorArgs++) {
+ if (!(*aValidator))
+ continue;
+ const ModuleBase_SelectionValidator* aSelValidator =
+ dynamic_cast<const ModuleBase_SelectionValidator*>(*aValidator);
+ if (!aSelValidator)
+ continue;
+ setActionEnabled(aId, aSelValidator->isValid(aSelection, *aValidatorArgs));
+
+ }
+ }
+}
+
+QKeySequence XGUI_ActionsMgr::registerShortcut(const QString& theKeySequence)
+{
+ if (theKeySequence.isEmpty()) {
+ return QKeySequence();
+ }
+ QKeySequence aResult(theKeySequence);
+ if (myShortcuts.contains(aResult)) {
+ QString aMessage = tr("Shortcut %1 is already defined. Ignore.").arg(theKeySequence);
+ Events_Error::send(aMessage.toStdString());
+ return QKeySequence();
+ }
+ myShortcuts.append(aResult);
+ return aResult;
+}
+
+void XGUI_ActionsMgr::processEvent(const std::shared_ptr<Events_Message>& theMessage)
+{
+ const Events_ID kResponseEvent =
+ Events_Loop::loop()->eventByName(EVENT_FEATURE_STATE_RESPONSE);
+ if (theMessage->eventID() == kResponseEvent) {
+ std::shared_ptr<ModelAPI_FeatureStateMessage> aStateMessage =
+ std::dynamic_pointer_cast<ModelAPI_FeatureStateMessage>(theMessage);
+ if (!aStateMessage.get())
+ return;
+ std::list<std::string> aFeaturesList = aStateMessage->features();
+ std::list<std::string>::iterator it = aFeaturesList.begin();
+ for( ; it != aFeaturesList.end(); ++it) {
+ QString anActionId = QString::fromStdString(*it);
+ bool theDefaultState = false;
+ if (myActions.contains(anActionId)) {
+ theDefaultState = myActions[anActionId]->isEnabled();
+ }
+ setActionEnabled(anActionId, aStateMessage->state(*it, theDefaultState));
+ }
+ } else if (theMessage.get()) {
+ #ifdef _DEBUG
+ std::cout << "XGUI_ActionsMgr::processEvent: unhandled message caught: " << std::endl
+ << theMessage->eventID().eventText() << std::endl;
+ #endif
+ }
+}
+
+void XGUI_ActionsMgr::setAllEnabled(bool isEnabled)
+{
+ foreach(QString eachAction, myActions.keys())
+ {
+ setActionEnabled(eachAction, isEnabled);
+ }
}
+
//!
void XGUI_ActionsMgr::setNestedCommandsEnabled(bool theEnabled, const QString& theParent)
{
}
}
+void XGUI_ActionsMgr::setNestedStackEnabled(ModuleBase_Operation* theOperation)
+{
+ if(!theOperation || !theOperation->feature())
+ return;
+ FeaturePtr aFeature = theOperation->feature();
+ QString aFeatureId = QString::fromStdString(aFeature->getKind());
+ setNestedCommandsEnabled(true, aFeatureId);
+
+ setNestedStackEnabled(myOperationMgr->previousOperation(theOperation));
+}
+
void XGUI_ActionsMgr::setActionChecked(const QString& theId, const bool theChecked)
{
if (myActions.contains(theId)) {
}
}
+void XGUI_ActionsMgr::setActionEnabled(const QString& theId, const bool theEnabled)
+{
+ if (myActions.contains(theId)) {
+ myActions[theId]->setEnabled(theEnabled);
+ }
+}
+
/*
* Disables all actions which have the Document Kind different to
* the current document's kind
}
}
-void XGUI_ActionsMgr::setActionEnabled(const QString& theId, const bool theEnabled)
-{
- if (myActions.contains(theId)) {
- myActions[theId]->setEnabled(theEnabled);
- }
-}
-
-void XGUI_ActionsMgr::updateCheckState()
-{
- QString eachCommand = QString();
- foreach(eachCommand, myActions.keys()) {
- setActionChecked(eachCommand, false);
- }
- QStringList ltActiveCommands = myOperationMgr->operationList();
- foreach(eachCommand, ltActiveCommands) {
- setActionChecked(eachCommand, true);
- }
-}
-
-QStringList XGUI_ActionsMgr::nestedCommands(const QString& theId) const
-{
- if (myNestedActions.contains(theId))
- return myNestedActions[theId];
- return QStringList();
-}
-
-bool XGUI_ActionsMgr::isNested(const QString& theId) const
-{
- foreach(QString aId, myNestedActions.keys())
- {
- QStringList aList = myNestedActions[aId];
- if (aList.contains(theId))
- return true;
- }
- return false;
-}
-
-QKeySequence XGUI_ActionsMgr::registerShortcut(const QString& theKeySequence)
+void XGUI_ActionsMgr::updateByPlugins(FeaturePtr anActiveFeature)
{
- if (theKeySequence.isEmpty()) {
- return QKeySequence();
- }
- QKeySequence aResult(theKeySequence);
- if (myShortcuts.contains(aResult)) {
- QString aMessage = tr("Shortcut %1 is already defined. Ignore.").arg(theKeySequence);
- Events_Error::send(aMessage.toStdString());
- return QKeySequence();
- }
- myShortcuts.append(aResult);
- return aResult;
+ static Events_ID aStateRequestEventId = Events_Loop::loop()->eventByName(
+ EVENT_FEATURE_STATE_REQUEST);
+ std::shared_ptr<ModelAPI_FeatureStateMessage> aMsg =
+ std::make_shared<ModelAPI_FeatureStateMessage>(aStateRequestEventId, this);
+ aMsg->setFeature(anActiveFeature);
+ Events_Loop::loop()->send(aMsg, false);
}
#include "XGUI.h"
+#include <Events_Listener.h>
+#include <ModelAPI_Feature.h>
+
#include <QObject>
#include <QMap>
#include <QList>
class ModuleBase_Operation;
class QAction;
-class XGUI_EXPORT XGUI_ActionsMgr : public QObject
+class XGUI_EXPORT XGUI_ActionsMgr : public QObject, public Events_Listener
{
Q_OBJECT
QKeySequence registerShortcut(const QString& theKeySequence);
- void updateByDocumentKind();
+ //! Redefinition of Events_Listener method
+ virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
public slots:
//! Update workbench actions according to OperationMgr state:
void update();
//! Sets all commands checked if it's operation is active.
void updateCheckState();
+ //! Updates actions according to current selection in the viewer
+ void updateOnViewSelection();
protected:
//! Sets all actions to isEnabled state.
void setAllEnabled(bool isEnabled);
- //! Sets to isEnabled state all siblings of the given operation and it's parents recursively
- void setNestedStackEnabled(ModuleBase_Operation* theOperation);
//! Sets all nested actions to isEnabled state for the command with given ID.
//! If ID is empty - all nested actions will be affected.
void setNestedCommandsEnabled(bool isEnabled, const QString& theParent = QString());
+ //! Sets to enabled state all siblings of the given operation and it's parents recursively
+ void setNestedStackEnabled(ModuleBase_Operation* theOperation);
//! Sets the action with theId to theChecked state.
void setActionChecked(const QString& theId, const bool theChecked);
//! Sets the action with theId to theEnabled state.
void setActionEnabled(const QString& theId, const bool theEnabled);
+ //! Updates actions according to their "document" tag
+ void updateByDocumentKind();
+ //! Asks plugins about their features state, using the Events system
+ void updateByPlugins(FeaturePtr theActiveFeature);
private:
QMap<QString, QAction*> myActions;
ModelAPI_ExecState aState = theFeature->data()->execState();
switch(aState) {
case ModelAPI_StateDone:
- case ModelAPI_StateNothing:
+ case ModelAPI_StateNothing: {
anIcon = QIcon(anIconString);
+ }
+ break;
case ModelAPI_StateMustBeUpdated: {
anIcon = ModuleBase_Tools::lighter(anIconString);
}
SLOT(onContextMenuCommand(const QString&, bool)));
myViewerProxy = new XGUI_ViewerProxy(this);
- connect(myViewerProxy, SIGNAL(selectionChanged()), this, SLOT(updateCommandsOnViewSelection()));
+ connect(myViewerProxy, SIGNAL(selectionChanged()),
+ myActionsMgr, SLOT(updateOnViewSelection()));
myModuleConnector = new XGUI_ModuleConnector(this);
connect(myOperationMgr, SIGNAL(operationAborted(ModuleBase_Operation*)),
SLOT(onOperationAborted(ModuleBase_Operation*)));
connect(myMainWindow, SIGNAL(exitKeySequence()), SLOT(onExit()));
- // TODO(sbh): It seems that application works properly without update on operationStarted
- connect(myOperationMgr, SIGNAL(operationStarted(ModuleBase_Operation*)),
- myActionsMgr, SLOT(update()));
- connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
- myActionsMgr, SLOT(update()));
connect(this, SIGNAL(errorOccurred(const QString&)), myErrorDlg, SLOT(addError(const QString&)));
}
myActionsMgr->update();
}
-//******************************************************
-QList<QAction*> XGUI_Workshop::getModuleCommands() const
-{
- QList<QAction*> aCommands;
- if (isSalomeMode()) { // update commands in SALOME mode
- aCommands = salomeConnector()->commandList();
- } else {
- AppElements_MainMenu* aMenuBar = myMainWindow->menuObject();
- foreach(AppElements_Command* aCmd, aMenuBar->features())
- {
- aCommands.append(aCmd);
- }
- }
- return aCommands;
-}
-
//******************************************************
QDockWidget* XGUI_Workshop::createObjectBrowser(QWidget* theParent)
{
}
-//**************************************************************
-void XGUI_Workshop::updateCommandsOnViewSelection()
-{
- XGUI_Selection* aSelection = mySelector->selection();
- if (aSelection->getSelected().size() == 0)
- return;
-
- // Restrict validators to manage only nested (child) features
- // of the current feature i.e. if current feature is Sketch -
- // Sketch Features & Constraints can be validated.
- QStringList aNestedIds;
- if(myOperationMgr->hasOperation()) {
- FeaturePtr aFeature = myOperationMgr->currentOperation()->feature();
- if(aFeature) {
- aNestedIds << myActionsMgr->nestedCommands(QString::fromStdString(aFeature->getKind()));
- }
- }
- SessionPtr aMgr = ModelAPI_Session::get();
- ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
- QList<QAction*> aActions = getModuleCommands();
- foreach(QAction* aAction, aActions) {
- QString aId = aAction->data().toString();
- if(!aNestedIds.contains(aId))
- continue;
- std::list<ModelAPI_Validator*> aValidators;
- std::list<std::list<std::string> > anArguments;
- aFactory->validators(aId.toStdString(), aValidators, anArguments);
- std::list<ModelAPI_Validator*>::iterator aValidator = aValidators.begin();
- for (; aValidator != aValidators.end(); aValidator++) {
- if (*aValidator) {
- const ModuleBase_SelectionValidator* aSelValidator =
- dynamic_cast<const ModuleBase_SelectionValidator*>(*aValidator);
- if (aSelValidator) {
- aAction->setEnabled(aSelValidator->isValid(aSelection));
- }
- }
- }
- }
-}
-
//**************************************************************
void XGUI_Workshop::registerValidators() const
{
{
return myActionsMgr;
}
- ;
//! Returns property panel widget
XGUI_PropertyPanel* propertyPanel() const
public slots:
void updateCommandStatus();
- void updateCommandsOnViewSelection();
void onNew();
void onOpen();
void validateOperation(const QString& theOperationId);
- QList<QAction*> getModuleCommands() const;
-
void displayAllResults();
void displayDocumentResults(DocumentPtr theDoc);
void displayGroupResults(DocumentPtr theDoc, std::string theGroup);