}
QWidget* ModuleBase_IWidgetCreator::createPanelByType(const std::string& theType,
- QWidget* theParent)
+ QWidget* theParent,
+ const FeaturePtr& theFeature)
{
return 0;
}
#include "ModuleBase.h"
+#include "ModelAPI_Feature.h"
+
#include <set>
#include <string>
#include <memory>
/// The default implementation is empty
/// \param theType a panel type
/// \param theParent a parent widget
+ /// \param theFeature a feature modified in the panel
/// \return created widget or null
virtual QWidget* createPanelByType(const std::string& theType,
- QWidget* theParent);
+ QWidget* theParent,
+ const FeaturePtr& theFeature);
/// Create page by its type
/// The default implementation is empty
return myPanelToCreator.contains(theType);
}
-QWidget* ModuleBase_WidgetCreatorFactory::createPanel(const std::string& theType, QWidget* theParent)
+QWidget* ModuleBase_WidgetCreatorFactory::createPanelByType(const std::string& theType,
+ QWidget* theParent,
+ const FeaturePtr& theFeature)
{
QWidget* aPanel = 0;
if (myPanelToCreator.contains(theType)) {
WidgetCreatorPtr aCreator = myPanelToCreator[theType];
- aPanel = aCreator->createPanelByType(theType, theParent);
+ aPanel = aCreator->createPanelByType(theType, theParent, theFeature);
}
return aPanel;
}
#include <ModuleBase_IWidgetCreator.h>
+#include <ModelAPI_Feature.h>
+
class ModuleBase_ModelWidget;
class ModuleBase_PageBase;
class ModuleBase_IWorkshop;
/// Create panel by its type
/// \param theType a type
/// \param theParent a parent widget
+ /// \param theFeature a feature to fill the panel
/// \return a created panel or null
- QWidget* createPanel(const std::string& theType, QWidget* theParent);
+ QWidget* createPanelByType(const std::string& theType, QWidget* theParent,
+ const FeaturePtr& theFeature);
/// Returns true if there is a creator, which can make a page by the type
/// \param theType a type
{
std::string aWType = myWidgetApi->widgetType();
if (aWType == NODE_FEATURE) {
- QWidget* aPanel = createPanel(thePage->pageWidget());
- if (aPanel) {
- thePage->addWidget(aPanel);
- thePage->alignToTop();
+ // if XML definition of the feature contains the next key, the widgets should not be created,
+ // but a specific panel should be made. However, to provide persistent of the panel values,
+ // we need to get into the panel the feature of the operation. As a result this panel should
+ // be created after the feature creating(create operation). The method setPanel() of this
+ // class is used for this. Here, we just return to avoid the widgets creation.
+ std::string aPanelName = myWidgetApi->getProperty(PROPERTY_PANEL_ID);
+ if (!aPanelName.empty())
return;
- }
}
if (!myWidgetApi->toChildWidget())
thePage->alignToTop();
}
+void ModuleBase_WidgetFactory::createPanel(ModuleBase_PageBase* thePage,
+ const FeaturePtr& theFeature)
+{
+ std::string aPanelName = myWidgetApi->getProperty(PROPERTY_PANEL_ID);
+ if (!aPanelName.empty() && ModuleBase_WidgetCreatorFactory::get()->hasPanelWidget(aPanelName)) {
+ QWidget* aPanel = ModuleBase_WidgetCreatorFactory::get()->createPanelByType(aPanelName,
+ thePage->pageWidget(), theFeature);
+ thePage->addWidget(aPanel);
+ thePage->alignToTop();
+ }
+}
+
void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage,
const std::string& theWidgetId)
{
} while (!theFound && myWidgetApi->toNextWidget());
}
-QWidget* ModuleBase_WidgetFactory::createPanel(QWidget* theParent)
-{
- QWidget* aPanel = 0;
- std::string aPanelName = myWidgetApi->getProperty(PROPERTY_PANEL_ID);
- if (!aPanelName.empty() && ModuleBase_WidgetCreatorFactory::get()->hasPanelWidget(aPanelName))
- aPanel = ModuleBase_WidgetCreatorFactory::get()->createPanel(aPanelName, theParent);
- return aPanel;
-}
-
ModuleBase_PageBase* ModuleBase_WidgetFactory::createPageByType(const std::string& theType,
QWidget* theParent)
{
/// \param thePage a parent page
void createWidget(ModuleBase_PageBase* thePage);
+ /// Creates property panel content for the feature
+ /// \param thePage a parent page
+ /// \param theFeature a feature to fill the panel
+ void createPanel(ModuleBase_PageBase* thePage, const FeaturePtr& theFeature);
+
/// Creates one widget for property panel for the widget with given index
/// \param theParent a parent widget
/// \param theWidgetId a widget index
/// check if ModuleBase_Widget has expandable widgets in getControls
bool hasExpandingControls(QWidget* theParent);
- /// creates panel control, if the corresponded parameter is provided by feature
- /// \param theParent a parent widget
- /// \return true if the panel is created
- QWidget* createPanel(QWidget* theParent);
-
/// Create page by its type
/// \param theType a type
/// \param theParent a parent widget
## Copyright (C) 2014-20xx CEA/DEN, EDF R&D
INCLUDE(Common)
-INCLUDE(UnitTest)
+SET(CMAKE_AUTOMOC ON)
SET(PROJECT_HEADERS
SamplePanelPlugin.h
#include "SamplePanelPlugin_Feature.h"
+#include "ModelAPI_AttributeInteger.h"
+
SamplePanelPlugin_Feature::SamplePanelPlugin_Feature()
: ModelAPI_Feature()
{
}
+
+void SamplePanelPlugin_Feature::initAttributes()
+{
+ data()->addAttribute(VALUE_ID(), ModelAPI_AttributeInteger::typeId());
+}
return MY_SAMPLE_PANEL_FEATURE_ID;
}
+ /// Total number of objects, initial and translated objects
+ inline static const std::string& VALUE_ID()
+ {
+ static const std::string MY_VALUE_ID("Value");
+ return MY_VALUE_ID;
+ }
+
/// Request for initialization of data model of the object: adding all attributes
- virtual void initAttributes() {};
+ virtual void initAttributes();
/// Returns the unique kind of a feature
virtual const std::string& getKind() {
// Author: Natalia ERMOLAEVA
#include <SamplePanelPlugin_Panel.h>
+#include <SamplePanelPlugin_Feature.h>
+
+#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_Events.h>
+
+#include <Events_Loop.h>
#include <QGridLayout>
#include <QLabel>
#include <QComboBox>
SamplePanelPlugin_Panel::SamplePanelPlugin_Panel(QWidget* theParent)
- : QWidget(theParent)
+: QWidget(theParent), myDefaultValue(0)
{
QGridLayout* aLayout = new QGridLayout(this);
aLayout->addWidget(new QLabel("Values:"), 0, 0);
- QComboBox* aComboBox = new QComboBox(this);
- aComboBox->addItem("Value_1");
- aComboBox->addItem("Value_2");
- aComboBox->addItem("Value_3");
+ myComboBox = new QComboBox(this);
+ myComboBox->addItem("Value_1");
+ myComboBox->addItem("Value_2");
+ myComboBox->addItem("Value_3");
+
+ connect(myComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
+ aLayout->addWidget(myComboBox, 0, 1);
+}
+
+void SamplePanelPlugin_Panel::setFeature(const FeaturePtr& theFeature)
+{
+ myFeature = theFeature;
+
+ AttributePtr anAttribute = myFeature->attribute(SamplePanelPlugin_Feature::VALUE_ID());
+ AttributeIntegerPtr aValueAttribute =
+ std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(anAttribute);
+ /// the attribute should be filled with some value, because Apply button of the Property
+ /// panel is enabled only if all attributes of the feature are initialized
+ /// It is possible to make it in the initializeAttribute method of the feature after
+ /// attribute creation
+ if (!aValueAttribute->isInitialized()) {
+ aValueAttribute->setValue(myDefaultValue);
+ /// to update error state of the feature: previous value was that this attribute is not
+ /// initialized yet. Apply of Property panel was disabled.
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ }
+
+ int aValueId = aValueAttribute->value();
+ myComboBox->setCurrentIndex(aValueId);
+}
+
+void SamplePanelPlugin_Panel::onCurrentIndexChanged(int theIndex)
+{
+ if (!myFeature.get())
+ return;
- aLayout->addWidget(aComboBox, 0, 1);
+ AttributePtr anAttribute = myFeature->attribute(SamplePanelPlugin_Feature::VALUE_ID());
+ AttributeIntegerPtr aValueAttribute =
+ std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(anAttribute);
+ aValueAttribute->setValue(theIndex);
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
}
#include <QWidget>
+#include <ModelAPI_Feature.h>
+
+class QComboBox;
+
/*!
* \ingroup GUI
- * Represent a property panel's list of ModuleBase_ModelWidgets.
+ * Represent a content of the property panel to show/modify parameters of some feature.
*/
class SamplePanelPlugin_Panel : public QWidget
{
+ Q_OBJECT
public:
/// Constructs a panel page
SamplePanelPlugin_Panel(QWidget* theParent);
/// Destructs the page
virtual ~SamplePanelPlugin_Panel() {}
+
+ /// Fill the panel by the feature
+ /// \param theFeature a feature to fill the panel controls
+ void setFeature(const FeaturePtr& theFeature);
+
+protected slots:
+ /// Update feature attribute by the current value of combo box
+ /// \param theIndex a combo box modified value
+ void onCurrentIndexChanged(int theIndex);
+
+private:
+ FeaturePtr myFeature; // the feature which corresponds to the current panel
+ QComboBox* myComboBox; // control for value attribute of the current feature
+ int myDefaultValue; /// the default combo box value
};
#endif /* SAMPLEPANELPLUGIN_PANEL_H_ */
}
QWidget* SamplePanelPlugin_WidgetCreator::createPanelByType(const std::string& theType,
- QWidget* theParent)
+ QWidget* theParent,
+ const FeaturePtr& theFeature)
{
QWidget* aWidget = 0;
if (myPanelTypes.find(theType) == myPanelTypes.end())
return aWidget;
if (theType == "QtPanel") {
- aWidget = new SamplePanelPlugin_Panel(theParent);
+ SamplePanelPlugin_Panel* aPanel = new SamplePanelPlugin_Panel(theParent);
+ aPanel->setFeature(theFeature);
+ aWidget = aPanel;
}
return aWidget;
/// Create panel control by its type.
/// \param theType a panel type
/// \param theParent a parent widget
+ /// \param theFeature a feature to fill the panel
/// \return created widget or null
virtual QWidget* createPanelByType(const std::string& theType,
- QWidget* theParent);
+ QWidget* theParent,
+ const FeaturePtr& theFeature);
private:
std::set<std::string> myPanelTypes; /// types of panels
};
#include "XGUI_ModuleConnector.h"
#include "XGUI_Workshop.h"
#include "XGUI_ErrorMgr.h"
-#include <XGUI_ObjectsBrowser.h>
+#include "XGUI_Tools.h"
+#include "XGUI_ObjectsBrowser.h"
#include <ModuleBase_IPropertyPanel.h>
#include <ModuleBase_ModelWidget.h>
bool isCompositeCommitted = false;
while (hasOperation()) {
ModuleBase_Operation* anOperation = currentOperation();
- if (workshop()->errorMgr()->isApplyEnabled()) {
+ if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled()) {
onCommitOperation();
} else {
abortOperation(anOperation);
ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
(currentOperation());
if(aFOperation && aFOperation->feature().get())
- workshop()->errorMgr()->updateActions(aFOperation->feature());
+ XGUI_Tools::workshop(myWorkshop)->errorMgr()->updateActions(aFOperation->feature());
}
void XGUI_OperationMgr::updateApplyOfOperations(ModuleBase_Operation* theOperation)
{
- XGUI_ErrorMgr* anErrorMgr = workshop()->errorMgr();
+ XGUI_ErrorMgr* anErrorMgr = XGUI_Tools::workshop(myWorkshop)->errorMgr();
if (theOperation) {
ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
if (aFOperation)
else if (canStopOperation(aCurrentOp)) {
// the started operation is granted in the parrent operation,
// e.g. current - Line in Sketch, started Circle
- if (workshop()->errorMgr()->isApplyEnabled() && aCurrentOp->isModified())
+ if (XGUI_Tools::workshop(myWorkshop)->errorMgr()->isApplyEnabled() && aCurrentOp->isModified())
aCurrentOp->commit();
else
abortOperation(aCurrentOp);
// after widget, object browser and viewer should process delete
/// other widgets such as line edit controls should not lead to
/// processing delete by workshop
- XGUI_ObjectsBrowser* aBrowser = workshop()->objectBrowser();
+ XGUI_ObjectsBrowser* aBrowser = XGUI_Tools::workshop(myWorkshop)->objectBrowser();
QWidget* aViewPort = myWorkshop->viewer()->activeViewPort();
// property panel child object is processed to process delete performed on Apply button of PP
if (theObject == aBrowser->treeView() ||
isChildObject(theObject, aViewPort) ||
isPPChildObject)
- workshop()->deleteObjects();
+ XGUI_Tools::workshop(myWorkshop)->deleteObjects();
isAccepted = true;
}
return isAccepted;
}
-XGUI_Workshop* XGUI_OperationMgr::workshop() const
-{
- XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
- return aConnector->workshop();
-}
-
bool XGUI_OperationMgr::isChildObject(const QObject* theObject, const QObject* theParent)
{
bool isPPChild = false;
void setWorkshop(ModuleBase_IWorkshop* theWorkshop)
{ myWorkshop = theWorkshop; };
+ /// Current workshop
+ ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
+
/// Returns the current operation or NULL
/// \return the current operation
ModuleBase_Operation* currentOperation() const;
void onOperationResumed();
private:
- XGUI_Workshop* workshop() const;
-
/// Checks if the object is a parent or a child under
/// \param theObject an investivated object
/// \param theParent a candidate to be a parent
#include <ModuleBase_Tools.h>
#include <ModuleBase_PageBase.h>
#include <ModuleBase_PageWidget.h>
+#include <ModuleBase_WidgetFactory.h>
+#include <ModuleBase_OperationDescription.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
repaint();
}
+void XGUI_PropertyPanel::createContentPanel(FeaturePtr theFeature)
+{
+ // Invalid feature case on abort of the operation
+ if (theFeature.get() == NULL)
+ return;
+ if (theFeature->isAction() || !theFeature->data())
+ return;
+
+ if (myWidgets.empty()) {
+ ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
+ QString aXmlRepr = anOperation->getDescription()->xmlRepresentation();
+
+ ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myOperationMgr->workshop());
+ aFactory.createPanel(contentWidget(), theFeature);
+ /// Apply button should be update if the feature was modified by the panel
+ myOperationMgr->onValidateOperation();
+ }
+}
+
void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
{
// it is possible that the property panel widgets have not been visualized
XGUI_OperationMgr* operationMgr() const { return myOperationMgr; }
public slots:
-
- /// \brief Update all widgets in property panel with values from the given feature
- /// \param theFeature a Feature to update values in widgets
+ /// \brief Update all widgets in property panel with values from the given feature
+ /// \param theFeature a Feature to update values in widgets
void updateContentWidget(FeaturePtr theFeature);
+ /// \brief If the XML definition of the feature contains information about specific
+ /// content of the property panel, it creates the panel and allow filling it by the given feature
+ /// \param theFeature a Feature to fill property panel
+ void createContentPanel(FeaturePtr theFeature);
+
/**
* Makes the given widget active, highlights it and removes
* highlighting from the previous active widget
if (anOperationMgr->startOperation(anOperation)) {
ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
- if (aFOperation)
+ if (aFOperation) {
workshop()->propertyPanel()->updateContentWidget(aFOperation->feature());
+ workshop()->propertyPanel()->createContentPanel(aFOperation->feature());
+ }
if (!anOperation->getDescription()->hasXmlRepresentation()) {
if (anOperation->commit())
workshop()->updateCommandStatus();