ModuleBase_IWorkshop.h
ModuleBase_ModelWidget.h
ModuleBase_Operation.h
+ ModuleBase_OperationAction.h
ModuleBase_OperationDescription.h
+ ModuleBase_OperationFeature.h
ModuleBase_PageBase.h
ModuleBase_PageGroupBox.h
ModuleBase_PageWidget.h
ModuleBase_IWorkshop.cpp
ModuleBase_ModelWidget.cpp
ModuleBase_Operation.cpp
- ModuleBase_OperationDescription.cpp
+ ModuleBase_OperationAction.cpp
+ ModuleBase_OperationDescription.cpp
+ ModuleBase_OperationFeature.cpp
ModuleBase_PageBase.cpp
ModuleBase_PageGroupBox.cpp
ModuleBase_PageWidget.cpp
#include "ModuleBase_Operation.h"
#include "ModuleBase_ISelection.h"
#include "ModuleBase_OperationDescription.h"
+#include "ModuleBase_OperationFeature.h"
#include <Events_Loop.h>
if (!myWorkshop->canStartOperation(theCmdId))
return;
- ModuleBase_Operation* anOperation = createOperation(theCmdId.toStdString());
- ModuleBase_ISelection* aSelection = myWorkshop->selection();
- // Initialise operation with preliminary selection
- anOperation->initSelection(aSelection, myWorkshop->viewer());
- sendOperation(anOperation);
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (createOperation(theCmdId.toStdString()));
+ if (aFOperation) {
+ ModuleBase_ISelection* aSelection = myWorkshop->selection();
+ // Initialise operation with preliminary selection
+ aFOperation->initSelection(aSelection, myWorkshop->viewer());
+ sendOperation(aFOperation);
+ }
}
ModuleBase_Operation* ModuleBase_IModule::getNewOperation(const std::string& theFeatureId)
{
- return new ModuleBase_Operation(theFeatureId.c_str(), this);
+ return new ModuleBase_OperationFeature(theFeatureId.c_str(), this);
}
ModuleBase_Operation* ModuleBase_IModule::createOperation(const std::string& theFeatureId)
{
- ModuleBase_Operation* anOperation = getNewOperation(theFeatureId);
-
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (getNewOperation(theFeatureId));
// If the operation is launched as sub-operation of another then we have to initialise
// parent feature
- ModuleBase_Operation* aCurOperation = myWorkshop->currentOperation();
+ ModuleBase_OperationFeature* aCurOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (myWorkshop->currentOperation());
if (aCurOperation) {
FeaturePtr aFeature = aCurOperation->feature();
CompositeFeaturePtr aCompFeature =
std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
if (aCompFeature) {
- anOperation->setParentFeature(aCompFeature);
+ aFOperation->setParentFeature(aCompFeature);
}
}
std::string aXmlCfg = aWdgReader.featureWidgetCfg(theFeatureId);
std::string aDescription = aWdgReader.featureDescription(theFeatureId);
- anOperation->getDescription()->setDescription(QString::fromStdString(aDescription));
- anOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
+ aFOperation->getDescription()->setDescription(QString::fromStdString(aDescription));
+ aFOperation->getDescription()->setXmlRepresentation(QString::fromStdString(aXmlCfg));
- return anOperation;
+ return aFOperation;
}
void ModuleBase_IModule::createFeatures()
if (!myWorkshop->canStartOperation(aFeatureId.c_str()))
return;
- ModuleBase_Operation* anOperation = createOperation(aFeatureId);
- anOperation->setFeature(theFeature);
- sendOperation(anOperation);
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (createOperation(aFeatureId));
+ if (aFOperation) {
+ aFOperation->setFeature(theFeature);
+ sendOperation(aFOperation);
+ }
}
bool ModuleBase_IModule::canActivateSelection(const ObjectPtr& theObject) const
{
- ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
- return !aOperation || !aOperation->hasObject(theObject);
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (myWorkshop->currentOperation());
+ return !aFOperation || !aFOperation->hasObject(theObject);
}
void ModuleBase_IModule::onOperationResumed(ModuleBase_Operation* theOperation)
ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* theParent)
: QObject(theParent),
- myIsEditing(false),
myIsModified(false),
myPropertyPanel(NULL)
{
ModuleBase_Operation::~ModuleBase_Operation()
{
delete myDescription;
- clearPreselection();
}
QString ModuleBase_Operation::id() const
return getDescription()->operationId();
}
-FeaturePtr ModuleBase_Operation::feature() const
-{
- return myFeature;
-}
-
bool ModuleBase_Operation::isValid() const
{
- if (!myFeature || !myFeature->data()->isValid())
- return true; // rename operation
- if (myFeature->isAction())
- return true;
- //Get validators for the Id
- SessionPtr aMgr = ModelAPI_Session::get();
- ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
- bool aValid = aFactory->validate(myFeature);
-
- // the feature exec state should be checked in order to do not apply features, which result can not
- // be built. E.g. extrusion on sketch, where the "to" is a perpendicular plane to the sketch
- bool isDone = ( myFeature->data()->execState() == ModelAPI_StateDone
- || myFeature->data()->execState() == ModelAPI_StateMustBeUpdated );
-
- return aValid && isDone;
+ return true;
}
-
bool ModuleBase_Operation::canBeCommitted() const
{
return isValid();
}
-FeaturePtr ModuleBase_Operation::createFeature(const bool theFlushMessage)
-{
- if (myParentFeature.get()) {
- myFeature = myParentFeature->addFeature(getDescription()->operationId().toStdString());
- } else {
- std::shared_ptr<ModelAPI_Document> aDoc = ModelAPI_Session::get()->activeDocument();
- myFeature = aDoc->addFeature(getDescription()->operationId().toStdString());
- }
- if (myFeature) { // TODO: generate an error if feature was not created
- myIsModified = true;
- // Model update should call "execute" of a feature.
- //myFeature->execute();
- // Init default values
- /*QList<ModuleBase_ModelWidget*> aWidgets = getDescription()->modelWidgets();
- QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
- for (; anIt != aLast; anIt++) {
- (*anIt)->storeValue(aFeature);
- }*/
- }
-
- if (theFlushMessage)
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
- return myFeature;
-}
-
-void ModuleBase_Operation::setFeature(FeaturePtr theFeature)
-{
- myFeature = theFeature;
- myIsEditing = true;
-}
-
-bool ModuleBase_Operation::hasObject(ObjectPtr theObj) const
-{
- FeaturePtr aFeature = feature();
- if (aFeature) {
- if (aFeature == theObj)
- return true;
- std::list<ResultPtr> aResults = aFeature->results();
- std::list<ResultPtr>::const_iterator aIt;
- for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
- if (theObj == (*aIt))
- return true;
- }
- }
- return false;
-}
void ModuleBase_Operation::start()
{
myIsModified = false;
+ /*
QString anId = getDescription()->operationId();
if (myIsEditing) {
anId = anId.append(EditSuffix());
startOperation();
emit started();
-
+*/
}
void ModuleBase_Operation::postpone()
void ModuleBase_Operation::abort()
{
+/*
// the viewer update should be blocked in order to avoid the features blinking before they are
// hidden
std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
Events_Loop::loop()->send(aMsg);
emit aborted();
+*/
}
bool ModuleBase_Operation::commit()
{
- if (canBeCommitted()) {
+/* if (canBeCommitted()) {
// the widgets of property panel should not process any events come from data mode
// after commit clicked. Some signal such as redisplay/create influence on content
// of the object browser and viewer context. Therefore it influence to the current
afterCommitOperation();
return true;
}
+*/
return false;
}
myIsModified = true;
}
-void ModuleBase_Operation::commitOperation()
-{
- if(!myPropertyPanel) {
- return;
- }
-}
-
-void ModuleBase_Operation::activateByPreselection()
-{
- if (myPreSelection.empty())
- return;
-
- ModuleBase_ModelWidget* aFilledWgt = 0;
- if (myPropertyPanel) {
- const QList<ModuleBase_ModelWidget*>& aWidgets = myPropertyPanel->modelWidgets();
- if (!aWidgets.empty()) {
- ModuleBase_ModelWidget* aWgt = 0;
- QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
- bool isSet = false;
- // 1. apply the selection to controls
- for (aWIt = aWidgets.constBegin(); aWIt != aWidgets.constEnd(); ++aWIt) {
- aWgt = (*aWIt);
- if (!aWgt->canSetValue())
- continue;
- myPropertyPanel->setPreselectionWidget(aWgt);
- if (!aWgt->setSelection(myPreSelection, true)) {
- isSet = false;
- break;
- } else {
- isSet = true;
- aFilledWgt = aWgt;
- }
- }
- myPropertyPanel->setPreselectionWidget(NULL);
- // in order to redisplay object in the viewer, the update/redisplay signals should be flushed
- // it is better to perform it not in setSelection of each widget, but do it here,
- // after the preselection is processed
- ModuleBase_ModelWidget::updateObject(myFeature);
-
- // 3. a signal should be emitted before the next widget activation
- // because, the activation of the next widget will give a focus to the widget. As a result
- // the value of the widget is initialized. And commit may happens until the value is entered.
- if (aFilledWgt)
- emit activatedByPreselection();
- }
- // 4. activate the next obligatory widget
- myPropertyPanel->activateNextWidget(aFilledWgt);
- }
-
- clearPreselection();
-}
-
-void ModuleBase_Operation::setParentFeature(CompositeFeaturePtr theParent)
-{
- myParentFeature = theParent;
-}
-
-CompositeFeaturePtr ModuleBase_Operation::parentFeature() const
-{
- return myParentFeature;
-}
-
-void ModuleBase_Operation::initSelection(ModuleBase_ISelection* theSelection,
- ModuleBase_IViewer* theViewer)
-{
- clearPreselection();
-
- QList<ModuleBase_ViewerPrs> aPreSelected;
- // Check that the selected result are not results of operation feature
- FeaturePtr aFeature = feature();
- if (aFeature) {
- QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected(ModuleBase_ISelection::AllControls);
-
- std::list<ResultPtr> aResults = aFeature->results();
- QObjectPtrList aResList;
- std::list<ResultPtr>::const_iterator aIt;
- for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
- aResList.append(*aIt);
-
- foreach (ModuleBase_ViewerPrs aPrs, aSelected) {
- if ((!aResList.contains(aPrs.object())) && (aPrs.object() != aFeature))
- aPreSelected.append(aPrs);
- }
- } else
- aPreSelected = theSelection->getSelected(ModuleBase_ISelection::AllControls);
-
- // convert the selection values to the values, which are set to the operation widgets
-
- //Handle(V3d_View) aView = theViewer->activeView();
- //foreach (ModuleBase_ViewerPrs aPrs, aPreSelected) {
- // ModuleBase_WidgetValueFeature* aValue = new ModuleBase_WidgetValueFeature();
- // aValue->setObject(aPrs.object());
-
- // double aX, anY;
- // if (getViewerPoint(aPrs, theViewer, aX, anY))
- // aValue->setPoint(std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, anY)));
- // myPreSelection.append(aValue);
- //}
- myPreSelection = aPreSelected;
-}
-
-
-bool ModuleBase_Operation::getViewerPoint(ModuleBase_ViewerPrs thePrs,
- ModuleBase_IViewer* theViewer,
- double& theX, double& theY)
-{
- return false;
-}
-
-void ModuleBase_Operation::clearPreselection()
-{
- myPreSelection.clear();
-}
-
void ModuleBase_Operation::setPropertyPanel(ModuleBase_IPropertyPanel* theProp)
{
myPropertyPanel = theProp;
- myPropertyPanel->setEditingMode(isEditOperation());
-
- if (myPropertyPanel) {
- const QList<ModuleBase_ModelWidget*>& aWidgets = myPropertyPanel->modelWidgets();
- QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
- for (aWIt = aWidgets.constBegin(); aWIt != aWidgets.constEnd(); ++aWIt) {
- ModuleBase_ModelWidget* aWgt = (*aWIt);
- connect(aWgt, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
- }
- }
-
- // Do not activate widgets by default if the current operation is editing operation
- // Because we don't know which widget is going to be edited.
- if (!isEditOperation()) {
- // 4. activate the first obligatory widget
- myPropertyPanel->activateNextWidget(NULL);
- }
}
bool ModuleBase_Operation::isGranted(QString theId) const
{
- return myNestedFeatures.contains(theId);
+ return false;
}
#define ModuleBase_Operation_H
#include <ModuleBase.h>
-#include <ModuleBase_ViewerPrs.h>
-
-#include <ModelAPI_CompositeFeature.h>
-#include <ModelAPI_Document.h>
#include <QObject>
#include <QString>
class ModuleBase_ModelWidget;
class ModuleBase_OperationDescription;
class ModuleBase_IPropertyPanel;
-class ModuleBase_ISelection;
-class ModuleBase_IViewer;
class QKeyEvent;
Q_OBJECT
public:
-
- /// Appends to operation's history id, if it is an "edit" operation (myIsEditing == true)
- static QString EditSuffix() { return "_E"; }
/// Constructor
/// \param theId the operation identifier
/// \param theParent the QObject parent
ModuleBase_Operation(const QString& theId = "", QObject* theParent = 0);
+
/// Destructor
virtual ~ModuleBase_Operation();
/// /returns the instance of the description class
ModuleBase_OperationDescription* getDescription() const { return myDescription; }
- /**
- * Must return true if this operation can be launched as nested for any current operation
- * and it is not necessary to check this operation on validity. By default
- * the operation is not granted.
- * The method has to be redefined for granted operations.
- */
+ /// Must return true if this operation can be launched as nested for any current operation
+ /// and it is not necessary to check this operation on validity. By default
+ /// the operation is not granted.
+ /// The method has to be redefined for granted operations.
virtual bool isGranted(QString theId) const;
-
/// Returns True if data of its feature was modified during operation
virtual bool isModified() const { return myIsModified; }
/// Change the modified state of the operation
void setIsModified(const bool theIsModified) { myIsModified = theIsModified; }
- /// Returns True id the current operation is launched in editing mode
- bool isEditOperation() const { return myIsEditing; }
-
- /// Returns list of nested features
- QStringList nestedFeatures() const { return myNestedFeatures; }
-
- /// Sets list of nested features
- void setNestedFeatures(const QStringList& theList) { myNestedFeatures = theList; }
-
-
/// Returns operations Id from it's description
QString id() const;
- /// Returns the operation feature
- /// \return the feature
- FeaturePtr feature() const;
-
- /**
- * Must return True if the operation's feature is valid.
- * Since IOperation does not have any feature returns false.
- */
+ /// Must return True if the operation's feature is valid.
+ /// Since IOperation does not have any feature returns false.
virtual bool isValid() const;
- /// Sets the operation feature
- void setFeature(FeaturePtr theFeature);
-
- /// Returns True if the current operation works with the given object (feature or result)
- virtual bool hasObject(ObjectPtr theObj) const;
-
- /// Initialisation of operation with preliminary selection
- /// \param theSelection an instance of Selection class
- /// \param theViewer a viewer to have the viewer the eye position
- virtual void initSelection(ModuleBase_ISelection* theSelection,
- ModuleBase_IViewer* theViewer);
-
/// \brief Set property pane to the operation
/// \param theProp a property panel instance
virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
/// \return Currently installed property panel
ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
- /// Activates widgets by preselection if it is accepted. Emits signal if the activation is correct
- virtual void activateByPreselection();
-
- /// If the operation works with feature which is sub-feature of another one
- /// then this variable has to be initialised by parent feature
- /// before operation feature creating
- void setParentFeature(CompositeFeaturePtr theParent);
-
- /// \return Installed parent feature (can be NULL)
- CompositeFeaturePtr parentFeature() const;
-
signals:
/// The operation is started
- void started();
+ void started();
/// The operation is aborted
- void aborted();
+ void aborted();
/// The operation is committed
- void committed();
+ void committed();
/// The operation is aborted or committed
- void stopped();
+ void stopped();
/// The operation is resumed
- void resumed();
+ void resumed();
/// The operation is postponed
- void postponed();
-
- /// The operation is filled with existing preselection
- void activatedByPreselection();
+ void postponed();
public slots:
/// Starts operation
/// to change behavior of operation. There is no point in using this method. It would
/// be better to inherit own operator from base one and redefine startOperation method
/// instead.
- void start();
+ virtual void start();
/// Deactivates current operation which can be resumed later.
- void postpone();
+ virtual void postpone();
/// Resumes operation
/// Public slot. Verifies whether operation can be started and starts operation.
/// to change behavior of operation. There is no point in using this method. It would
/// be better to inherit own operator from base one and redefine startOperation method
/// instead.
- void resume();
+ virtual void resume();
/// Aborts operation
/// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
/// Redefine abortOperation method to change behavior of operation instead
- void abort();
+ virtual void abort();
/// Commits operation
/// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
/// Redefine commitOperation method to change behavior of operation instead
- bool commit();
+ virtual bool commit();
/// Changes the modified flag of the operation
void onValuesChanged();
virtual void abortOperation() {}
/// Virtual method called when operation committed (see commit() method for more description)
- virtual void commitOperation();
+ virtual void commitOperation() {};
/// Virtual method called after operation committed (see commit() method for more description)
virtual void afterCommitOperation() {}
/// Virtual method called after operation resume (see resume() method for more description)
virtual void resumeOperation() {}
- /// Creates an operation new feature
- /// \param theFlushMessage the flag whether the create message should be flushed
- /// \returns the created feature
- virtual FeaturePtr createFeature(const bool theFlushMessage = true);
-
/// Verifies whether this operator can be commited.
/// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
virtual bool canBeCommitted() const;
- /// Return a widget value point by the selection and the viewer position
- /// The default realization returns false
- /// \param thePrs the presentation
- /// \param theViewer a viewer to have the viewer the eye position
- /// \param theX the horizontal coordinate
- /// \param theY the vertical coordinate
- /// \return true if the point exits in the selection
- virtual bool getViewerPoint(ModuleBase_ViewerPrs thePrs,
- ModuleBase_IViewer* theViewer,
- double& theX, double& theY);
-
- /// Removes the preselection information and clears the map of preselection
- void clearPreselection();
-
- protected:
- /// The operation feature to be handled
- FeaturePtr myFeature;
-
+private:
/// the container to have the operation description
- ModuleBase_OperationDescription* myDescription;
-
- /// Editing feature flag
- bool myIsEditing;
+ ModuleBase_OperationDescription* myDescription;
/// Modified feature flag
bool myIsModified;
- /// List of nested operations IDs
- QStringList myNestedFeatures;
-
- /// List of pre-selected object
- QList<ModuleBase_ViewerPrs> myPreSelection;
-
/// Access to property panel
ModuleBase_IPropertyPanel* myPropertyPanel;
-
- /// If the operation works with feature which is sub-feature of another one
- /// then this variable has to be initialised by parent feature
- /// before operation feature creating
- CompositeFeaturePtr myParentFeature;
-
- /// Last current feature before editing operation
- FeaturePtr myCurrentFeature;
};
#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+/*
+ * ModuleBase_OperationAction.cpp
+ *
+ * Created on: Apr 2, 2014
+ * Author: sbh
+ */
+
+#include "ModuleBase_OperationAction.h"
+
+ModuleBase_OperationAction::ModuleBase_OperationAction(const QString& theId, QObject* theParent)
+ : ModuleBase_Operation(theId, theParent)
+{
+}
+
+ModuleBase_OperationAction::~ModuleBase_OperationAction()
+{
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+/*
+ * ModuleBase_OperationAction.h
+ *
+ * Created on: Apr 2, 2014
+ * Author: sbh
+ */
+
+#ifndef ModuleBase_OperationAction_H
+#define ModuleBase_OperationAction_H
+
+#include <ModuleBase.h>
+
+#include <ModuleBase_Operation.h>
+
+/*!
+ * \class ModuleBase_OperationAction
+ * \ingroup GUI
+ * \brief Base class for all operations
+ *
+ * Base class for all operations. If you perform an action it is reasonable to create
+ * operation intended for this. This is a base class for all operations which provides
+ * mechanism for correct starting operations, starting operations above already started
+ * ones, committing operations and so on. To create own operation it is reasonable to
+ * inherit it from this class and redefines virtual methods to provide own behavior
+ */
+
+class MODULEBASE_EXPORT ModuleBase_OperationAction : public ModuleBase_Operation
+{
+Q_OBJECT
+
+ public:
+
+ /// Constructor
+ /// \param theId the operation identifier
+ /// \param theParent the QObject parent
+ ModuleBase_OperationAction(const QString& theId = "", QObject* theParent = 0);
+ /// Destructor
+ virtual ~ModuleBase_OperationAction();
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+/*
+ * ModuleBase_OperationFeature.cpp
+ *
+ * Created on: Apr 2, 2014
+ * Author: sbh
+ */
+
+#include "ModuleBase_OperationFeature.h"
+
+#include "ModuleBase_OperationDescription.h"
+#include "ModuleBase_ModelWidget.h"
+#include "ModuleBase_ViewerPrs.h"
+#include "ModuleBase_IPropertyPanel.h"
+#include "ModuleBase_ISelection.h"
+#include "ModuleBase_IViewer.h"
+
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_Events.h>
+#include <ModelAPI_Result.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_Session.h>
+
+#include <GeomAPI_Pnt2d.h>
+
+#include <Events_Loop.h>
+
+#include <QTimer>
+
+#ifdef _DEBUG
+#include <QDebug>
+#endif
+
+ModuleBase_OperationFeature::ModuleBase_OperationFeature(const QString& theId, QObject* theParent)
+: ModuleBase_Operation(theId, theParent),
+ myIsEditing(false)
+{
+}
+
+ModuleBase_OperationFeature::~ModuleBase_OperationFeature()
+{
+ clearPreselection();
+}
+
+FeaturePtr ModuleBase_OperationFeature::feature() const
+{
+ return myFeature;
+}
+
+bool ModuleBase_OperationFeature::isValid() const
+{
+ if (!myFeature || !myFeature->data()->isValid())
+ return true; // rename operation
+ if (myFeature->isAction())
+ return true;
+ //Get validators for the Id
+ SessionPtr aMgr = ModelAPI_Session::get();
+ ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+ bool aValid = aFactory->validate(myFeature);
+
+ // the feature exec state should be checked in order to do not apply features, which result can not
+ // be built. E.g. extrusion on sketch, where the "to" is a perpendicular plane to the sketch
+ bool isDone = ( myFeature->data()->execState() == ModelAPI_StateDone
+ || myFeature->data()->execState() == ModelAPI_StateMustBeUpdated );
+
+ return aValid && isDone;
+}
+
+FeaturePtr ModuleBase_OperationFeature::createFeature(const bool theFlushMessage)
+{
+ if (myParentFeature.get()) {
+ myFeature = myParentFeature->addFeature(getDescription()->operationId().toStdString());
+ } else {
+ std::shared_ptr<ModelAPI_Document> aDoc = ModelAPI_Session::get()->activeDocument();
+ myFeature = aDoc->addFeature(getDescription()->operationId().toStdString());
+ }
+ if (myFeature) { // TODO: generate an error if feature was not created
+ setIsModified(true);
+ // Model update should call "execute" of a feature.
+ //myFeature->execute();
+ // Init default values
+ /*QList<ModuleBase_ModelWidget*> aWidgets = getDescription()->modelWidgets();
+ QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
+ for (; anIt != aLast; anIt++) {
+ (*anIt)->storeValue(aFeature);
+ }*/
+ }
+
+ if (theFlushMessage)
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+ return myFeature;
+}
+
+void ModuleBase_OperationFeature::setFeature(FeaturePtr theFeature)
+{
+ myFeature = theFeature;
+ myIsEditing = true;
+}
+
+bool ModuleBase_OperationFeature::hasObject(ObjectPtr theObj) const
+{
+ FeaturePtr aFeature = feature();
+ if (aFeature) {
+ if (aFeature == theObj)
+ return true;
+ std::list<ResultPtr> aResults = aFeature->results();
+ std::list<ResultPtr>::const_iterator aIt;
+ for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
+ if (theObj == (*aIt))
+ return true;
+ }
+ }
+ return false;
+}
+
+void ModuleBase_OperationFeature::start()
+{
+ setIsModified(false);
+ QString anId = getDescription()->operationId();
+ if (myIsEditing) {
+ anId = anId.append(EditSuffix());
+ }
+ ModelAPI_Session::get()->startOperation(anId.toStdString());
+
+ startOperation();
+
+ if (!myIsEditing) {
+ FeaturePtr aFeature = createFeature();
+ // if the feature is not created, there is no sense to start the operation
+ if (aFeature.get() == NULL) {
+ // it is necessary to abor the operation in the session and emit the aborted signal
+ // in order to update commands status in the workshop, to be exact the feature action
+ // to be unchecked
+ abort();
+ return;
+ }
+ }
+ /// Set current feature and remeber old current feature
+ if (myIsEditing) {
+ SessionPtr aMgr = ModelAPI_Session::get();
+ DocumentPtr aDoc = aMgr->activeDocument();
+ myCurrentFeature = aDoc->currentFeature(true);
+ aDoc->setCurrentFeature(feature(), false);
+ }
+
+ startOperation();
+ emit started();
+
+}
+
+void ModuleBase_OperationFeature::abort()
+{
+ // the viewer update should be blocked in order to avoid the features blinking before they are
+ // hidden
+ std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
+ new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)));
+ Events_Loop::loop()->send(aMsg);
+
+ // the widgets of property panel should not process any events come from data mode
+ // after abort clicked. Some signal such as redisplay/create influence on content
+ // of the object browser and viewer context. Therefore it influence to the current
+ // selection and if the active widget listens it, the attribute value is errnoneous
+ // changed.
+ ModuleBase_IPropertyPanel* aPropertyPanel = propertyPanel();
+ if (aPropertyPanel)
+ aPropertyPanel->cleanContent();
+
+ SessionPtr aMgr = ModelAPI_Session::get();
+ if (myIsEditing) {
+ DocumentPtr aDoc = aMgr->activeDocument();
+ bool aIsOp = aMgr->isOperation();
+ if (!aIsOp)
+ aMgr->startOperation();
+ aDoc->setCurrentFeature(myCurrentFeature, true);
+ if (!aIsOp)
+ aMgr->finishOperation();
+ myCurrentFeature = FeaturePtr();
+ }
+ abortOperation();
+
+ stopOperation();
+ // is is necessary to deactivate current widgets before the model operation is aborted
+ // because abort removes the feature and activated filters should not check it
+ propertyPanel()->cleanContent();
+
+ aMgr->abortOperation();
+ emit stopped();
+ // the viewer update should be unblocked in order to avoid the features blinking before they are
+ // hidden
+ aMsg = std::shared_ptr<Events_Message>(
+ new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)));
+
+ Events_Loop::loop()->send(aMsg);
+
+ emit aborted();
+}
+
+bool ModuleBase_OperationFeature::commit()
+{
+ if (canBeCommitted()) {
+ // the widgets of property panel should not process any events come from data mode
+ // after commit clicked. Some signal such as redisplay/create influence on content
+ // of the object browser and viewer context. Therefore it influence to the current
+ // selection and if the active widget listens it, the attribute value is errnoneous
+ // changed.
+ ModuleBase_IPropertyPanel* aPropertyPanel = propertyPanel();
+ if (aPropertyPanel)
+ aPropertyPanel->cleanContent();
+
+ SessionPtr aMgr = ModelAPI_Session::get();
+ /// Set current feature and remeber old current feature
+ if (myIsEditing) {
+ DocumentPtr aDoc = aMgr->activeDocument();
+ bool aIsOp = aMgr->isOperation();
+ if (!aIsOp)
+ aMgr->startOperation();
+ aDoc->setCurrentFeature(myCurrentFeature, true);
+ if (!aIsOp)
+ aMgr->finishOperation();
+ myCurrentFeature = FeaturePtr();
+ }
+ commitOperation();
+ aMgr->finishOperation();
+
+ stopOperation();
+ emit stopped();
+ emit committed();
+
+ afterCommitOperation();
+ return true;
+ }
+ return false;
+}
+
+void ModuleBase_OperationFeature::activateByPreselection()
+{
+ if (myPreSelection.empty())
+ return;
+
+ ModuleBase_ModelWidget* aFilledWgt = 0;
+ ModuleBase_IPropertyPanel* aPropertyPanel = propertyPanel();
+ if (aPropertyPanel) {
+ const QList<ModuleBase_ModelWidget*>& aWidgets = aPropertyPanel->modelWidgets();
+ if (!aWidgets.empty()) {
+ ModuleBase_ModelWidget* aWgt = 0;
+ QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
+ bool isSet = false;
+ // 1. apply the selection to controls
+ for (aWIt = aWidgets.constBegin(); aWIt != aWidgets.constEnd(); ++aWIt) {
+ aWgt = (*aWIt);
+ if (!aWgt->canSetValue())
+ continue;
+ aPropertyPanel->setPreselectionWidget(aWgt);
+ if (!aWgt->setSelection(myPreSelection, true)) {
+ isSet = false;
+ break;
+ } else {
+ isSet = true;
+ aFilledWgt = aWgt;
+ }
+ }
+ aPropertyPanel->setPreselectionWidget(NULL);
+ // in order to redisplay object in the viewer, the update/redisplay signals should be flushed
+ // it is better to perform it not in setSelection of each widget, but do it here,
+ // after the preselection is processed
+ ModuleBase_ModelWidget::updateObject(myFeature);
+
+ // 3. a signal should be emitted before the next widget activation
+ // because, the activation of the next widget will give a focus to the widget. As a result
+ // the value of the widget is initialized. And commit may happens until the value is entered.
+ if (aFilledWgt)
+ emit activatedByPreselection();
+ }
+ // 4. activate the next obligatory widget
+ aPropertyPanel->activateNextWidget(aFilledWgt);
+ }
+
+ clearPreselection();
+}
+
+void ModuleBase_OperationFeature::setParentFeature(CompositeFeaturePtr theParent)
+{
+ myParentFeature = theParent;
+}
+
+CompositeFeaturePtr ModuleBase_OperationFeature::parentFeature() const
+{
+ return myParentFeature;
+}
+
+void ModuleBase_OperationFeature::initSelection(ModuleBase_ISelection* theSelection,
+ ModuleBase_IViewer* theViewer)
+{
+ clearPreselection();
+
+ QList<ModuleBase_ViewerPrs> aPreSelected;
+ // Check that the selected result are not results of operation feature
+ FeaturePtr aFeature = feature();
+ if (aFeature) {
+ QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected(ModuleBase_ISelection::AllControls);
+
+ std::list<ResultPtr> aResults = aFeature->results();
+ QObjectPtrList aResList;
+ std::list<ResultPtr>::const_iterator aIt;
+ for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
+ aResList.append(*aIt);
+
+ foreach (ModuleBase_ViewerPrs aPrs, aSelected) {
+ if ((!aResList.contains(aPrs.object())) && (aPrs.object() != aFeature))
+ aPreSelected.append(aPrs);
+ }
+ } else
+ aPreSelected = theSelection->getSelected(ModuleBase_ISelection::AllControls);
+
+ myPreSelection = aPreSelected;
+}
+
+void ModuleBase_OperationFeature::clearPreselection()
+{
+ myPreSelection.clear();
+}
+
+void ModuleBase_OperationFeature::setPropertyPanel(ModuleBase_IPropertyPanel* theProp)
+{
+ ModuleBase_Operation::setPropertyPanel(theProp);
+
+ theProp->setEditingMode(isEditOperation());
+
+ if (theProp) {
+ const QList<ModuleBase_ModelWidget*>& aWidgets = theProp->modelWidgets();
+ QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
+ for (aWIt = aWidgets.constBegin(); aWIt != aWidgets.constEnd(); ++aWIt) {
+ ModuleBase_ModelWidget* aWgt = (*aWIt);
+ connect(aWgt, SIGNAL(valuesChanged()), this, SLOT(onValuesChanged()));
+ }
+ }
+
+ // Do not activate widgets by default if the current operation is editing operation
+ // Because we don't know which widget is going to be edited.
+ if (!isEditOperation()) {
+ // 4. activate the first obligatory widget
+ theProp->activateNextWidget(NULL);
+ }
+}
+
+bool ModuleBase_OperationFeature::isGranted(QString theId) const
+{
+ return myNestedFeatures.contains(theId);
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+/*
+ * ModuleBase_OperationFeature.h
+ *
+ * Created on: Apr 2, 2014
+ * Author: sbh
+ */
+
+#ifndef ModuleBase_OperationFeature_H
+#define ModuleBase_OperationFeature_H
+
+#include <ModuleBase.h>
+#include <ModuleBase_Operation.h>
+#include <ModuleBase_ViewerPrs.h>
+
+#include <ModelAPI_CompositeFeature.h>
+
+#include <QObject>
+#include <QString>
+#include <QStringList>
+
+class ModuleBase_ModelWidget;
+class ModuleBase_ISelection;
+class ModuleBase_IViewer;
+
+class QKeyEvent;
+
+/*!
+ * \class ModuleBase_OperationFeature
+ * \ingroup GUI
+ * \brief Base class for all operations
+ *
+ * Base class for all operations. If you perform an action it is reasonable to create
+ * operation intended for this. This is a base class for all operations which provides
+ * mechanism for correct starting operations, starting operations above already started
+ * ones, committing operations and so on. To create own operation it is reasonable to
+ * inherit it from this class and redefines virtual methods to provide own behavior
+ * Main virtual methods are
+ * - virtual bool isReadyToStart();
+ * - virtual void startOperation();
+ * - virtual void abortOperation();
+ * - virtual void commitOperation();
+ */
+
+class MODULEBASE_EXPORT ModuleBase_OperationFeature : public ModuleBase_Operation
+{
+Q_OBJECT
+
+ public:
+
+ /// Appends to operation's history id, if it is an "edit" operation (myIsEditing == true)
+ static QString EditSuffix() { return "_E"; }
+ /// Constructor
+ /// \param theId the operation identifier
+ /// \param theParent the QObject parent
+ ModuleBase_OperationFeature(const QString& theId = "", QObject* theParent = 0);
+ /// Destructor
+ virtual ~ModuleBase_OperationFeature();
+
+ /**
+ * Must return true if this operation can be launched as nested for any current operation
+ * and it is not necessary to check this operation on validity. By default
+ * the operation is not granted.
+ * The method has to be redefined for granted operations.
+ */
+ virtual bool isGranted(QString theId) const;
+
+ /// Returns True id the current operation is launched in editing mode
+ bool isEditOperation() const { return myIsEditing; }
+
+ /// Returns list of nested features
+ QStringList nestedFeatures() const { return myNestedFeatures; }
+
+ /// Sets list of nested features
+ void setNestedFeatures(const QStringList& theList) { myNestedFeatures = theList; }
+
+ /// Returns the operation feature
+ /// \return the feature
+ FeaturePtr feature() const;
+
+ /**
+ * Must return True if the operation's feature is valid.
+ * Since IOperation does not have any feature returns false.
+ */
+ virtual bool isValid() const;
+
+ /// Sets the operation feature
+ void setFeature(FeaturePtr theFeature);
+
+ /// Returns True if the current operation works with the given object (feature or result)
+ virtual bool hasObject(ObjectPtr theObj) const;
+
+ /// Initialisation of operation with preliminary selection
+ /// \param theSelection an instance of Selection class
+ /// \param theViewer a viewer to have the viewer the eye position
+ virtual void initSelection(ModuleBase_ISelection* theSelection,
+ ModuleBase_IViewer* theViewer);
+
+ /// \brief Set property pane to the operation
+ /// \param theProp a property panel instance
+ virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
+
+ /// \return Currently installed property panel
+ //ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
+
+ /// Activates widgets by preselection if it is accepted. Emits signal if the activation is correct
+ virtual void activateByPreselection();
+
+ /// If the operation works with feature which is sub-feature of another one
+ /// then this variable has to be initialised by parent feature
+ /// before operation feature creating
+ void setParentFeature(CompositeFeaturePtr theParent);
+
+ /// \return Installed parent feature (can be NULL)
+ CompositeFeaturePtr parentFeature() const;
+
+signals:
+ /// The operation is filled with existing preselection
+ void activatedByPreselection();
+
+ public slots:
+ /// Starts operation
+ /// Public slot. Verifies whether operation can be started and starts operation.
+ /// This slot is not virtual and cannot be redefined. Redefine startOperation method
+ /// to change behavior of operation. There is no point in using this method. It would
+ /// be better to inherit own operator from base one and redefine startOperation method
+ /// instead.
+ void start();
+
+ /// Aborts operation
+ /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
+ /// Redefine abortOperation method to change behavior of operation instead
+ void abort();
+
+ /// Commits operation
+ /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
+ /// Redefine commitOperation method to change behavior of operation instead
+ bool commit();
+
+ protected:
+ /// Creates an operation new feature
+ /// \param theFlushMessage the flag whether the create message should be flushed
+ /// \returns the created feature
+ virtual FeaturePtr createFeature(const bool theFlushMessage = true);
+
+ /// Removes the preselection information and clears the map of preselection
+ void clearPreselection();
+
+ protected:
+ /// The operation feature to be handled
+ FeaturePtr myFeature;
+
+ /// Editing feature flag
+ bool myIsEditing;
+
+ /// List of nested operations IDs
+ QStringList myNestedFeatures;
+
+ /// List of pre-selected object
+ QList<ModuleBase_ViewerPrs> myPreSelection;
+
+ /// If the operation works with feature which is sub-feature of another one
+ /// then this variable has to be initialised by parent feature
+ /// before operation feature creating
+ CompositeFeaturePtr myParentFeature;
+
+ /// Last current feature before editing operation
+ FeaturePtr myCurrentFeature;
+};
+
+#endif
#include <ModuleBase_ISelection.h>
#include <ModuleBase_Operation.h>
+#include <ModuleBase_OperationFeature.h>
#include <XGUI_ModuleConnector.h>
#include <XGUI_Workshop.h>
bool isUseTransaction = false;
// 1. change auxiliary type of a created feature
if (PartSet_SketcherMgr::isNestedCreateOperation(anOperation) &&
- PartSet_SketcherMgr::isEntity(anOperation->id().toStdString()) ) {
- anObjects.append(anOperation->feature());
+ PartSet_SketcherMgr::isEntity(anOperation->id().toStdString()) ) {
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (anOperation);
+ if (aFOperation)
+ anObjects.append(aFOperation->feature());
}
else {
isUseTransaction = true;
// 1. change auxiliary type of a created feature
if (PartSet_SketcherMgr::isNestedCreateOperation(anOperation) &&
PartSet_SketcherMgr::isEntity(anOperation->id().toStdString()) ) {
- anObjects.append(anOperation->feature());
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
+ if (aFOperation)
+ anObjects.append(aFOperation->feature());
}
else {
/// The operation should not be aborted here, because the method does not changed
#include <ModuleBase_WidgetValidated.h>
#include <ModuleBase_FilterFactory.h>
#include <ModuleBase_Tools.h>
-#include <GeomValidators_ShapeType.h>
+#include <ModuleBase_OperationFeature.h>
+#include <GeomValidators_ShapeType.h>
#include <GeomValidators_Face.h>
#include <GeomValidators_ConstructionComposite.h>
#include <GeomValidators_ZeroOffset.h>
mySketchMgr->commitNestedSketch(theOperation);
}
- if (theOperation->isEditOperation())
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+ if (!aFOperation || aFOperation->isEditOperation())
return;
// the selection is cleared after commit the create operation
// in order to do not use the same selected objects in the restarted operation
aWorkshop->selector()->clearSelection();
/// Restart sketcher operations automatically
- FeaturePtr aFeature = theOperation->feature();
+ FeaturePtr aFeature = aFOperation->feature();
std::shared_ptr<SketchPlugin_Feature> aSPFeature =
std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
if (aSPFeature && (myRestartingMode == RM_LastFeatureUsed ||
myRestartingMode == RM_EmptyFeatureUsed)) {
- myLastOperationId = theOperation->id();
- myLastFeature = myRestartingMode == RM_LastFeatureUsed ? theOperation->feature() : FeaturePtr();
+ myLastOperationId = aFOperation->id();
+ myLastFeature = myRestartingMode == RM_LastFeatureUsed ? aFOperation->feature() : FeaturePtr();
launchOperation(myLastOperationId);
}
mySketchMgr->startNestedSketch(theOperation);
}
- myCustomPrs->activate(theOperation->feature());
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+ if (aFOperation)
+ myCustomPrs->activate(aFOperation->feature());
}
void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
if (isSketchOp || isNestedOp) {
// in active sketch operation it is possible to activate operation object in selection
// in the edit operation, e.g. points of the line can be moved when the line is edited
- aCanActivate = aCanActivate || anOperation->isEditOperation();
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
+ aCanActivate = aCanActivate || (aFOperation && aFOperation->isEditOperation());
}
return aCanActivate;
}
void PartSet_Module::propertyPanelDefined(ModuleBase_Operation* theOperation)
{
- ModuleBase_IPropertyPanel* aPanel = theOperation->propertyPanel();
- if (PartSet_SketcherMgr::isSketchOperation(theOperation) && (theOperation->isEditOperation())) {
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+ if (!aFOperation)
+ return;
+
+ ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
+ if (PartSet_SketcherMgr::isSketchOperation(aFOperation) && (aFOperation->isEditOperation())) {
// we have to manually activate the sketch label in edit mode
aPanel->activateWidget(aPanel->modelWidgets().first());
return;
}
// Restart last operation type
- if ((theOperation->id() == myLastOperationId) && myLastFeature) {
+ if ((aFOperation->id() == myLastOperationId) && myLastFeature) {
ModuleBase_ModelWidget* aWgt = aPanel->activeWidget();
- if (theOperation->id().toStdString() == SketchPlugin_Line::ID()) {
+ if (aFOperation->id().toStdString() == SketchPlugin_Line::ID()) {
// Initialise new line with first point equal to end of previous
PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(aWgt);
if (aPnt2dWgt) {
std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(SketchPlugin_Line::END_ID()));
if (aPoint) {
aPnt2dWgt->setPoint(aPoint->x(), aPoint->y());
- PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), theOperation->feature(),
+ PartSet_Tools::setConstraints(mySketchMgr->activeSketch(), aFOperation->feature(),
aWgt->attributeID(), aPoint->x(), aPoint->y());
aPanel->activateNextWidget(aPnt2dWgt);
}
#include <ModuleBase_IWorkshop.h>
#include <ModuleBase_IViewWindow.h>
#include <ModuleBase_Operation.h>
+#include <ModuleBase_OperationFeature.h>
#include <ModuleBase_ISelection.h>
#include <ModuleBase_IPropertyPanel.h>
#include <ModuleBase_Operation.h>
// not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
// port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
// presentation becomes valid and redisplay happens
- ModuleBase_Operation* aOperation = getCurrentOperation();
- if (aOperation) {
- FeaturePtr aFeature = aOperation->feature();
+ //ModuleBase_Operation* aOperation = getCurrentOperation();
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (getCurrentOperation());
+ if (aFOperation) {
+ FeaturePtr aFeature = aFOperation->feature();
if (aFeature.get() && aFeature->data()->isValid()) {
- visualizeFeature(aOperation, canDisplayObject(aFeature), false);
+ visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
}
}
}
// hides the presentation of the current operation feature
// the feature is to be erased here, but it is correct to call canDisplayObject because
// there can be additional check (e.g. editor widget in distance constraint)
- FeaturePtr aFeature = getCurrentOperation()->feature();
- visualizeFeature(aOperation, canDisplayObject(aFeature));
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (getCurrentOperation());
+ if (aFOperation) {
+ FeaturePtr aFeature = aFOperation->feature();
+ visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
+ }
}
void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
// visualize the current operation feature
myIsResetCurrentValue = false;
operationMgr()->onValidateOperation();
- ModuleBase_Operation* aOperation = getCurrentOperation();
// the feature is to be erased here, but it is correct to call canDisplayObject because
// there can be additional check (e.g. editor widget in distance constraint)
- FeaturePtr aFeature = getCurrentOperation()->feature();
- visualizeFeature(aOperation, canDisplayObject(aFeature));
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (getCurrentOperation());
+ if (aFOperation) {
+ FeaturePtr aFeature = aFOperation->feature();
+ visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
+ }
}
void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
if (!aViewer->canDragByMouse())
return;
- ModuleBase_Operation* aOperation = getCurrentOperation();
- if (aOperation && aOperation->isEditOperation()) {
- ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (getCurrentOperation());
+ if (!aFOperation)
+ return;
+
+ if (aFOperation->isEditOperation()) {
+ ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
ModuleBase_ModelWidget* aActiveWgt = aPanel->activeWidget();
// If the current widget is a selector, do nothing, it processes the mouse press
if(aActiveWgt && aActiveWgt->isViewerSelector()) {
}
// Use only for sketch operations
- if (aOperation && myCurrentSketch) {
+ if (myCurrentSketch) {
if (!PartSet_Tools::sketchPlane(myCurrentSketch))
return;
- bool isSketcher = isSketchOperation(aOperation);
- bool isSketchOpe = isNestedSketchOperation(aOperation);
+ bool isSketcher = isSketchOperation(aFOperation);
+ bool isSketchOpe = isNestedSketchOperation(aFOperation);
// Avoid non-sketch operations
if ((!isSketchOpe) && (!isSketcher))
return;
- bool isEditing = aOperation->isEditOperation();
+ bool isEditing = aFOperation->isEditOperation();
// Ignore creation sketch operation
if ((!isSketcher) && (!isEditing))
if (myCurrentSelection.empty()) {
if (isSketchOpe && (!isSketcher))
// commit previous operation
- if (!aOperation->commit())
- aOperation->abort();
+ if (!aFOperation->commit())
+ aFOperation->abort();
return;
}
// Init flyout point for radius rotation
}
} else if (isSketchOpe && isEditing) {
// If selected another object commit current result
- aOperation->commit();
+ aFOperation->commit();
myIsDragging = true;
get2dPoint(theWnd, theEvent, myCurrentPoint);
}
// the feature is to be erased here, but it is correct to call canDisplayObject because
// there can be additional check (e.g. editor widget in distance constraint)
- FeaturePtr aFeature = getCurrentOperation()->feature();
- visualizeFeature(aOperation, canDisplayObject(aFeature));
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (getCurrentOperation());
+ if (aFOperation) {
+ FeaturePtr aFeature = aFOperation->feature();
+ visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
+ }
}
myClickedPoint.clear();
void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
{
- ModuleBase_Operation* aOperation = getCurrentOperation();
- if (aOperation && aOperation->isEditOperation()) {
- std::string aId = aOperation->id().toStdString();
- if (isDistanceOperation(aOperation))
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (getCurrentOperation());
+ if (aFOperation && aFOperation->isEditOperation()) {
+ std::string aId = aFOperation->id().toStdString();
+ if (isDistanceOperation(aFOperation))
{
// Activate dimension value editing on double click
- ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel();
+ ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
// Find corresponded widget to activate value editing
foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation)
{
- return theOperation && !theOperation->isEditOperation() && isNestedSketchOperation(theOperation);
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (theOperation);
+ return aFOperation && !aFOperation->isEditOperation() && isNestedSketchOperation(aFOperation);
}
bool PartSet_SketcherMgr::isEntity(const std::string& theId)
void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
{
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (getCurrentOperation());
+ if (!aFOperation)
+ return;
+
myModule->onViewTransformed();
// Display all sketcher sub-Objects
- myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theOperation->feature());
+ myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
// Hide sketcher result
bool aHasPlane = false;
std::shared_ptr<GeomAPI_Pln> aPln;
- if (theOperation->isEditOperation()) {
+ if (aFOperation->isEditOperation()) {
// If it is editing of sketch then it means that plane is already defined
aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
if (aPln.get())
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
// all sketch objects should be activated in the sketch selection modes by edit operation start
// in case of creation operation, there is an active widget, which activates own selection mode
- if (theOperation->isEditOperation() && aHasPlane)
+ if (aFOperation->isEditOperation() && aHasPlane)
aConnector->activateModuleSelectionModes();
}
-void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
+void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation*/* theOperation*/)
{
myIsMouseOverWindow = false;
myIsConstraintsShown = true;
void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
{
if (isNestedCreateOperation(theOperation)) {
- FeaturePtr aFeature = theOperation->feature();
- // it is necessary to check the the feature data validity because
- // some kind of features are removed by an operation commit(the macro state of a feature)
- if (aFeature.get() && aFeature->data()->isValid()) {
- visualizeFeature(theOperation, true);
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (theOperation);
+ if (aFOperation) {
+ FeaturePtr aFeature = aFOperation->feature();
+ // it is necessary to check the the feature data validity because
+ // some kind of features are removed by an operation commit(the macro state of a feature)
+ if (aFeature.get() && aFeature->data()->isValid()) {
+ visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
+ }
}
}
}
// 3. the method should not filter the objects, which are not related to the current operation.
// The object is filtered just if it is a current operation feature or this feature result
bool isObjectFound = false;
- ModuleBase_Operation* anOperation = getCurrentOperation();
- if (anOperation) {
- FeaturePtr aFeature = anOperation->feature();
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (getCurrentOperation());
+ if (aFOperation) {
+ FeaturePtr aFeature = aFOperation->feature();
if (aFeature.get()) {
std::list<ResultPtr> aResults = aFeature->results();
if (theObject == aFeature)
return myModule->workshop()->currentOperation();
}
-void PartSet_SketcherMgr::visualizeFeature(ModuleBase_Operation* theOperation,
+void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
+ const bool isEditOperation,
const bool isToDisplay,
const bool isFlushRedisplay)
{
return;
#endif
- if (!theOperation || theOperation->isEditOperation())
+ if (isEditOperation || !theFeature.get())
return;
ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
// 1. change visibility of the object itself, here the presentable object is processed,
// e.g. constraints features
- FeaturePtr aFeature = theOperation->feature();
- std::list<ResultPtr> aResults = aFeature->results();
+ //FeaturePtr aFeature = aFOperation->feature();
+ std::list<ResultPtr> aResults = theFeature->results();
if (isToDisplay)
- aFeature->setDisplayed(true);
+ theFeature->setDisplayed(true);
else
- aFeature->setDisplayed(false);
+ theFeature->setDisplayed(false);
// change visibility of the object results, e.g. non-constraint features
std::list<ResultPtr>::const_iterator aIt;
/// a current value is changed by property panel, the feature is displayed otherwise it is hidden
/// \param theOperation an operation which feature is to be displayed, it is nested create operation
/// \param isToDisplay a flag about the display or erase the feature
- void visualizeFeature(ModuleBase_Operation* theOperation, const bool isToDisplay,
- const bool isFlushRedisplay = true);
+ void visualizeFeature(const FeaturePtr& theFeature, const bool isEditOperation,
+ const bool isToDisplay, const bool isFlushRedisplay = true);
private:
/// Gives a debug information about internal flags myIsMouseOverWindow and myIsResetCurrentValue
/// \return a string value
#include <ModuleBase_Tools.h>
#include <ModuleBase_Operation.h>
#include <ModuleBase_IPropertyPanel.h>
+#include <ModuleBase_OperationFeature.h>
#include <Config_WidgetAPI.h>
#include <QLabel>
std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
FeaturePtr aSketch = aCompFeature->addFeature("Sketch");
- ModuleBase_Operation* anOperation = myModule->createOperation("Sketch");
- anOperation->setFeature(aSketch);
- myModule->sendOperation(anOperation);
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (myModule->createOperation("Sketch"));
+ if (aFOperation)
+ aFOperation->setFeature(aSketch);
+ myModule->sendOperation(aFOperation);
//connect(anOperation, SIGNAL(aborted()), aWorkshop->operationMgr(), SLOT(abortAllOperations()));
} else {
// Break current operation
#include <ModelAPI_Events.h>
#include <ModelAPI_Validator.h>
#include <ModuleBase_Operation.h>
+#include <ModuleBase_OperationFeature.h>
#include <ModuleBase_SelectionValidator.h>
void XGUI_ActionsMgr::update()
{
FeaturePtr anActiveFeature = FeaturePtr();
- if (myOperationMgr->hasOperation()) {
- ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
- anActiveFeature = anOperation->feature();
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (myOperationMgr->currentOperation());
+ if (aFOperation) {
+ anActiveFeature = aFOperation->feature();
if(anActiveFeature.get()) {
setAllEnabled(false);
QString aFeatureId = QString::fromStdString(anActiveFeature->getKind());
setActionEnabled(aFeatureId, true);
}
- setNestedStackEnabled(anOperation);
+ setNestedStackEnabled(aFOperation);
} else {
setAllEnabled(true);
setNestedCommandsEnabled(false);
void XGUI_ActionsMgr::setNestedStackEnabled(ModuleBase_Operation* theOperation)
{
- if(!theOperation || !theOperation->feature())
+ ModuleBase_OperationFeature* anOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+ if(!anOperation || !anOperation->feature())
return;
- FeaturePtr aFeature = theOperation->feature();
+ FeaturePtr aFeature = anOperation->feature();
QString aFeatureId = QString::fromStdString(aFeature->getKind());
setActionEnabled(aFeatureId, true);
setNestedCommandsEnabled(true, aFeatureId);
#include <ModuleBase_IPropertyPanel.h>
#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_OperationFeature.h>
#include <ModelAPI_Attribute.h>
#include <ModelAPI_Session.h>
void XGUI_ErrorMgr::onValidationStateChanged()
{
XGUI_OperationMgr* anOperationMgr = dynamic_cast<XGUI_OperationMgr*>(sender());
- if (!anOperationMgr || !anOperationMgr->currentOperation())
+ if (!anOperationMgr)
return;
-
- if (!myPropertyPanel)
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (anOperationMgr->currentOperation());
+ if (!myPropertyPanel || !aFOperation)
return;
// get feature
- FeaturePtr aFeature = anOperationMgr->currentOperation()->feature();
+ FeaturePtr aFeature = aFOperation->feature();
if (!aFeature.get() || !aFeature->data()->isValid())
return;
#include "ModuleBase_IWorkshop.h"
#include "ModuleBase_IModule.h"
#include "ModuleBase_OperationDescription.h"
+#include "ModuleBase_OperationFeature.h"
#include "ModelAPI_CompositeFeature.h"
#include "ModelAPI_Session.h"
{
QStringList result;
foreach(ModuleBase_Operation* eachOperation, myOperations) {
- FeaturePtr aFeature = eachOperation->feature();
- if(aFeature) {
- result << QString::fromStdString(aFeature->getKind());
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(eachOperation);
+ if (aFOperation) {
+ FeaturePtr aFeature = aFOperation->feature();
+ if(aFeature) {
+ result << QString::fromStdString(aFeature->getKind());
+ }
}
}
return result;
} else {
abortOperation(anOperation);
}
- FeaturePtr aFeature = anOperation->feature();
- CompositeFeaturePtr aComposite =
- std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
- isCompositeCommitted = aComposite.get();
- if (isCompositeCommitted)
- break;
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (anOperation);
+ if (aFOperation) {
+ FeaturePtr aFeature = aFOperation->feature();
+ CompositeFeaturePtr aComposite =
+ std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
+ isCompositeCommitted = aComposite.get();
+ if (isCompositeCommitted)
+ break;
+ }
}
return true;
}
#include <ModuleBase_SelectionValidator.h>
#include <ModuleBase_Tools.h>
#include <ModuleBase_WidgetFactory.h>
+#include <ModuleBase_OperationFeature.h>
#include <Config_Common.h>
#include <Config_FeatureMessage.h>
{
setNestedFeatures(theOperation);
- if (theOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
- setPropertyPanel(theOperation);
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (theOperation);
+ if (!aFOperation)
+ return;
+
+ if (aFOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel
+ setPropertyPanel(aFOperation);
// filling the operation values by the current selection
// if the operation can be commited after the controls filling, the method perform should
// be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch)
- if (!theOperation->isEditOperation()) {
- theOperation->activateByPreselection();
- if (operationMgr()->currentOperation() != theOperation)
+ if (!aFOperation->isEditOperation()) {
+ aFOperation->activateByPreselection();
+ if (operationMgr()->currentOperation() != aFOperation)
return;
}
}
updateCommandStatus();
- myModule->onOperationStarted(theOperation);
+ myModule->onOperationStarted(aFOperation);
// the objects of the current operation should be deactivated
QObjectPtrList anObjects;
- FeaturePtr aFeature = theOperation->feature();
+ FeaturePtr aFeature = aFOperation->feature();
anObjects.append(aFeature);
std::list<ResultPtr> aResults = aFeature->results();
std::list<ResultPtr>::const_iterator aIt;
//******************************************************
void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
{
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (theOperation);
+ if (!aFOperation)
+ return;
+
ModuleBase_ISelection* aSel = mySelector->selection();
QObjectPtrList aObj = aSel->selectedPresentations();
//!< No need for property panel
hidePropertyPanel();
myPropertyPanel->cleanContent();
- myModule->onOperationStopped(theOperation);
+ myModule->onOperationStopped(aFOperation);
// the deactivated objects of the current operation should be activated back.
// They were deactivated on operation start or an object redisplay
QObjectPtrList anObjects;
- FeaturePtr aFeature = theOperation->feature();
+ FeaturePtr aFeature = aFOperation->feature();
if (myDisplayer->isVisible(aFeature) && !myDisplayer->isActive(aFeature))
anObjects.append(aFeature);
std::list<ResultPtr> aResults = aFeature->results();
void XGUI_Workshop::setNestedFeatures(ModuleBase_Operation* theOperation)
{
- if (this->isSalomeMode())
- theOperation->setNestedFeatures(mySalomeConnector->nestedActions(theOperation->id()));
- else
- theOperation->setNestedFeatures(myActionsMgr->nestedCommands(theOperation->id()));
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+ if (!aFOperation)
+ return;
+
+ if (isSalomeMode())
+ aFOperation->setNestedFeatures(mySalomeConnector->nestedActions(theOperation->id()));
+ else
+ aFOperation->setNestedFeatures(myActionsMgr->nestedCommands(theOperation->id()));
}
void XGUI_Workshop::setPropertyPanel(ModuleBase_Operation* theOperation)
{
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
+ if (!aFOperation)
+ return;
+
showPropertyPanel();
- QString aXmlRepr = theOperation->getDescription()->xmlRepresentation();
+ QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
myModuleConnector);
QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
- bool isStoreValue = !theOperation->isEditOperation() &&
+ bool isStoreValue = !aFOperation->isEditOperation() &&
!aWidget->getDefaultValue().empty() &&
!aWidget->isComputedDefault();
- aWidget->setFeature(theOperation->feature(), isStoreValue);
+ aWidget->setFeature(aFOperation->feature(), isStoreValue);
aWidget->enableFocusProcessing();
}
myPropertyPanel->setModelWidgets(aWidgets);
- theOperation->setPropertyPanel(myPropertyPanel);
+ aFOperation->setPropertyPanel(myPropertyPanel);
myModule->propertyPanelDefined(theOperation);
std::list<std::string>::const_iterator it = theList.cbegin();
for (; it != theList.cend(); it++) {
QString anId = QString::fromStdString(*it);
- bool isEditing = anId.endsWith(ModuleBase_Operation::EditSuffix());
+ bool isEditing = anId.endsWith(ModuleBase_OperationFeature::EditSuffix());
if (isEditing) {
- anId.chop(ModuleBase_Operation::EditSuffix().size());
+ anId.chop(ModuleBase_OperationFeature::EditSuffix().size());
}
ActionInfo anInfo;
QAction* aContextMenuAct = myContextMenuMgr->actionByName(anId);
#include <ModuleBase_Operation.h>
#include <ModuleBase_OperationDescription.h>
+#include <ModuleBase_OperationFeature.h>
#include <ModuleBase_Tools.h>
#include <ModuleBase_IViewer.h>
#include <ModuleBase_FilterFactory.h>
XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
if (anOperationMgr->startOperation(anOperation)) {
- workshop()->propertyPanel()->updateContentWidget(anOperation->feature());
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
+ if (aFOperation)
+ workshop()->propertyPanel()->updateContentWidget(aFOperation->feature());
if (!anOperation->getDescription()->hasXmlRepresentation()) {
if (anOperation->commit())
workshop()->updateCommandStatus();
}
//******************************************************
-void XGUI_WorkshopListener::onFeatureUpdatedMsg(const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
+void XGUI_WorkshopListener::onFeatureUpdatedMsg(
+ const std::shared_ptr<ModelAPI_ObjectUpdatedMessage>& theMsg)
{
std::set<ObjectPtr> aFeatures = theMsg->objects();
XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
if (anOperationMgr->hasOperation()) {
- FeaturePtr aCurrentFeature = anOperationMgr->currentOperation()->feature();
- std::set<ObjectPtr>::const_iterator aIt;
- for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
- ObjectPtr aNewFeature = (*aIt);
- if (aNewFeature == aCurrentFeature) {
- workshop()->propertyPanel()->updateContentWidget(aCurrentFeature);
- break;
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (anOperationMgr->currentOperation());
+ if (aFOperation) {
+ FeaturePtr aCurrentFeature = aFOperation->feature();
+ std::set<ObjectPtr>::const_iterator aIt;
+ for (aIt = aFeatures.begin(); aIt != aFeatures.end(); ++aIt) {
+ ObjectPtr aNewFeature = (*aIt);
+ if (aNewFeature == aCurrentFeature) {
+ workshop()->propertyPanel()->updateContentWidget(aCurrentFeature);
+ break;
+ }
}
}
}