Model_ResultConstruction.h
Model_ResultPart.h
Model_ResultValidators.h
+ Model_FeatureValidator.h
)
SET(PROJECT_SOURCES
Model_ResultConstruction.cpp
Model_ResultPart.cpp
Model_ResultValidators.cpp
+ Model_FeatureValidator.cpp
)
SET(PROJECT_LIBRARIES
--- /dev/null
+// File: Model_FeatureValidator.cpp
+// Created: 8 Jul 2014
+// Author: Vitaly SMETANNIKOV
+
+#include <Model_FeatureValidator.h>
+#include <ModelAPI_Attribute.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Object.h>
+
+#include <list>
+#include <boost/shared_ptr.hpp>
+
+bool Model_FeatureValidator::isValid(const boost::shared_ptr<ModelAPI_Feature>& theFeature
+ /*, const std::string theAttr*/
+ /*, std::list<std::string> theArguments*/) const
+{
+ boost::shared_ptr<ModelAPI_Data> aData = theFeature->data();
+ if(!aData->isValid())
+ return false;
+ const std::string kAllTypes = "";
+ std::list<AttributePtr> aLtAttributes = aData->attributes(kAllTypes);
+ std::list<AttributePtr>::iterator it = aLtAttributes.begin();
+ for( ; it != aLtAttributes.end(); it++) {
+ if(!(*it)->isInitialized()) return false;
+ }
+ return true;
+}
--- /dev/null
+// File: ModelAPI_FeatureValidator.h
+// Created: 8 Jul 2014
+// Author: Vitaly SMETANNIKOV
+
+#ifndef Model_FeatureValidator_H
+#define Model_FeatureValidator_H
+
+#include <Model.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_FeatureValidator.h>
+
+#include <boost/shared_ptr.hpp>
+
+class Model_FeatureValidator: public ModelAPI_FeatureValidator
+{
+public:
+ /// Returns true if feature and/or attributes are valid
+ /// \param theFeature the validated feature
+ MODEL_EXPORT virtual bool isValid(const boost::shared_ptr<ModelAPI_Feature>& theFeature) const;
+};
+
+#endif
#include <Model_Validator.h>
#include <Model_ResultValidators.h>
+#include <Model_FeatureValidator.h>
#include <ModelAPI_Feature.h>
#include <Events_Error.h>
registerValidator("Model_ResultPointValidator", new Model_ResultPointValidator);
registerValidator("Model_ResultLineValidator", new Model_ResultLineValidator);
registerValidator("Model_ResultArcValidator", new Model_ResultArcValidator);
+ registerValidator("Model_FeatureValidator", new Model_FeatureValidator);
}
return aIt->second;
}
return NULL;
-}
\ No newline at end of file
+}
};
+//! Pointer on attribute object
+typedef boost::shared_ptr<ModelAPI_Attribute> AttributePtr;
+
#endif
#include "ModelAPI.h"
#include "ModelAPI_Validator.h"
-class MODELAPI_EXPORT ModelAPI_FeatureValidator: public ModelAPI_Validator
+class ModelAPI_FeatureValidator: public ModelAPI_Validator
{
public:
/// Returns true if feature and/or attributes are valid
/// \param theFeature the validated feature
/// \param theAttr the validated attribute ID, empty string of feature is validated
/// \param theArguments list of string, feature attribute names: dependent attributes
- virtual bool validate(const boost::shared_ptr<ModelAPI_Feature>& theFeature,
- const std::string theAttr, std::list<std::string> theArguments) const = 0;
+ virtual bool isValid(const boost::shared_ptr<ModelAPI_Feature>& theFeature) const = 0;
};
#endif
<feature id="SketchLine" title="Line" tooltip="Create a new line" icon=":icons/line.png">
<point_selector id="StartPoint" title="Start point" tooltip="Start point of the line" previous_feature_param="EndPoint"/>
<point_selector id="EndPoint" title="End point" tooltip="End point of the line"/>
+ <validator id="Model_FeatureValidator" />
</feature>
<feature id="SketchCircle" title="Circle" tooltip="Create a new circle" icon=":icons/circle.png">
<point_selector id="CircleCenter" title="Center" tooltip="Center of the circle"/>
return aList;
}
-QList<XGUI_Workbench*> XGUI_MainMenu::workbenches() const
-{
- QList<XGUI_Workbench*> aList;
- for (int aTabIdx = 0; aTabIdx < myMenuTabs->count(); ++aTabIdx) {
- XGUI_Workbench* aWb = dynamic_cast<XGUI_Workbench*>(myMenuTabs->widget(aTabIdx));
- if (aWb) {
- aList.append(aWb);
- }
- }
- return aList;
-}
-
int XGUI_MainMenu::menuItemSize() const
{
//TODO(sbh, vsv): get this value from the preferences
//! Returns list of created commands
QList<XGUI_Command*> features() const;
- QList<XGUI_Workbench*> workbenches() const;
-
virtual bool eventFilter(QObject *theWatched, QEvent *theEvent);
//! Displays given console as a tab in the workbench
//! Removes already created tab with python console
void removeConsole();
+ //! Defines size of menu item.
+ //! In the future this value should be extracted from the preferences.
int menuItemSize() const;
+ //! Defines number of menu item rows.
+ //! In the future this value should be extracted from the preferences.
int menuItemRowsCount() const;
+ //! Defines height of the main menu. (Number of rows * row height)
int menuHeight() const;
private:
XGUI_MainWindow::XGUI_MainWindow(QWidget* parent)
: QMainWindow(parent),
- myPythonConsole(0),
- myIsConsoleDocked(false)
+ myPythonConsole(0)
{
setWindowTitle(tr("New Geom"));
createMainMenu();
public slots:
void showPythonConsole();
void hidePythonConsole();
+ //! Python console can be a dock widget
void dockPythonConsole();
+ //! or can be a tab in the main menu.
void undockPythonConsole();
void createSubWindow();
XGUI_Viewer* myViewer;
PyConsole_EnhConsole* myPythonConsole;
- //! Python console can be a dock widget if true, else as the tab.
- bool myIsConsoleDocked;
};
class XGUI_EXPORT CloseEventWatcher: public QObject {
#include "XGUI_OperationMgr.h"
#include "ModuleBase_Operation.h"
+#include <ModelAPI_Validator.h>
+#include <ModelAPI_FeatureValidator.h>
#include <QMessageBox>
#include <QApplication>
this, SIGNAL(activateNextWidget(ModuleBase_ModelWidget*)));
theOperation->start();
+ validateCurrentOperation();
return true;
}
return result;
}
+void XGUI_OperationMgr::validateOperation(ModuleBase_Operation* theOperation)
+{
+ //Get operation Id and feature to validate
+ QString anOperationId = theOperation->id();
+ FeaturePtr aFeature = theOperation->feature();
+ //Get validators for the Id
+ PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
+ ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+ std::list<ModelAPI_Validator*> aValidators;
+ aFactory->validators(anOperationId.toStdString(), aValidators);
+ //
+ std::list<ModelAPI_Validator*>::iterator it = aValidators.begin();
+ bool isValid = true;
+ for(; it != aValidators.end(); it++) {
+ const ModelAPI_FeatureValidator* aFeatureValidator =
+ dynamic_cast<const ModelAPI_FeatureValidator*>(*it);
+ if (!aFeatureValidator) continue;
+ if (!aFeatureValidator->isValid(aFeature)) {
+ isValid = false;
+ break;
+ }
+ }
+ emit operationValidated(isValid);
+}
+
+void XGUI_OperationMgr::validateCurrentOperation()
+{
+ if(!hasOperation())
+ return;
+ ModuleBase_Operation* anOperation = currentOperation();
+ validateOperation(currentOperation());
+}
+
bool XGUI_OperationMgr::eventFilter(QObject *theObject, QEvent *theEvent)
{
if (theEvent->type() == QEvent::KeyRelease) {
virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
+public slots:
+ void validateCurrentOperation();
+
signals:
/// Signal about an operation is started. It is emitted after the start() of operation is done.
void operationStarted();
void operationStopped(ModuleBase_Operation* theOperation);
/// Signal about an operation is resumed. It is emitted after the resume() of operation is done.
void operationResumed();
+ /// Signal is emitted after the validate methods calls.
+ void operationValidated(bool);
/// Signal about the necessety of the next widget activating
/// \param theWidget the model widget
void activateNextWidget(ModuleBase_ModelWidget* theWidget);
/// Returns true if the operation can be aborted
bool canAbortOperation();
+ void validateOperation(ModuleBase_Operation* theOperation);
+
protected slots:
/// Slot that commits the current operation.
void onCommitOperation();
}
emit widgetActivated(aNextWidget);
}
+
+void XGUI_PropertyPanel::setAcceptEnabled(bool isEnabled)
+{
+ QPushButton* anOkBtn = findChild<QPushButton*>(XGUI::PROP_PANEL_OK);
+ anOkBtn->setEnabled(isEnabled);
+}
/// slot to activate the next widget in the property panel
/// \param theWidget a widget. The next widget should be activated
void onActivateNextWidget(ModuleBase_ModelWidget* theWidget);
+ // Enables / disables "ok" ("accept") button
+ void setAcceptEnabled(bool);
signals:
/// The signal about key release on the control, that corresponds to the attribute
}
}
}
+ myOperationMgr->validateCurrentOperation();
}
//******************************************************
{
//std::set<ObjectPtr> aFeatures = theMsg->objects();
}
-
+
//******************************************************
void XGUI_Workshop::onOperationStarted()
{
showPropertyPanel();
QString aXmlRepr = aOperation->getDescription()->xmlRepresentation();
- ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(), myModuleConnector);
+ ModuleBase_WidgetFactory aFactory = ModuleBase_WidgetFactory(aXmlRepr.toStdString(),
+ myModuleConnector);
myPropertyPanel->cleanContent();
aFactory.createWidget(myPropertyPanel->contentWidget());
aCommands = salomeConnector()->commandList();
} else {
XGUI_MainMenu* aMenuBar = myMainWindow->menuObject();
- foreach (XGUI_Workbench* aWb, aMenuBar->workbenches()) {
- foreach(XGUI_Command* aCmd, aWb->features())
- aCommands.append(aCmd);
+ foreach(XGUI_Command* aCmd, aMenuBar->features()) {
+ aCommands.append(aCmd);
}
}
return aCommands;
myOperationMgr, SLOT(onWidgetActivated(ModuleBase_ModelWidget*)));
connect(myOperationMgr, SIGNAL(activateNextWidget(ModuleBase_ModelWidget*)),
myPropertyPanel, SLOT(onActivateNextWidget(ModuleBase_ModelWidget*)));
+ connect(myOperationMgr, SIGNAL(operationValidated(bool)),
+ myPropertyPanel, SLOT(setAcceptEnabled(bool)));
+
}
//******************************************************
void onFeatureRedisplayMsg(const ModelAPI_ObjectUpdatedMessage* theMsg);
void onObjectDeletedMsg(const ModelAPI_ObjectDeletedMessage* theMsg);
+ void validateOperation(const QString& theOperationId);
+
QList<QAction*> getModuleCommands() const;
void displayAllResults();