std::string aIcon = getProperty(theNode, NODE_ICON);
std::string aEmpty = getProperty(theNode, SHOW_EMPTY);
+ std::string aFeatures = getProperty(theNode, FOLDER_FEATURES);
std::string::iterator aIt;
for (aIt = aEmpty.begin(); aIt != aEmpty.end(); aIt++) {
(*aIt) = toupper(*aIt);
myRootFolderTypes.push_back(aGroupType);
myRootFolderIcons.push_back(aIcon);
myRootFolderShowEmpty.push_back(aIsEmpty);
+ myRootFeaturesList.push_back(aFeatures);
} else {
mySubFolderNames.push_back(aName);
mySubFolderTypes.push_back(aGroupType);
mySubFolderIcons.push_back(aIcon);
mySubFolderShowEmpty.push_back(aIsEmpty);
+ mySubFeaturesList.push_back(aFeatures);
}
} else if (isNode(theNode, ROOT_DOCUMENT, NULL)) {
isRootReading = true;
}
return -1;
}
+
+std::string getFolderFeatures(const std::string& theFolderName,
+ const std::vector<std::string>& theNames,
+ const std::vector<std::string>& theFeatures)
+{
+ int aId;
+ bool aFound = false;
+ std::vector<std::string>::const_iterator aIt;
+ for(aIt = theNames.cbegin(), aId = 0; aIt != theNames.cend(); ++aIt, ++aId) {
+ if ((*aIt) == theFolderName) {
+ aFound = true;
+ break;
+ }
+ }
+ if (aFound)
+ return theFeatures.at(aId);
+ return std::string();
+}
+
+std::string Config_DataModelReader::
+ subFolderFeatures(const std::string& theFolderName) const
+{
+ return getFolderFeatures(theFolderName, mySubFolderNames, mySubFeaturesList);
+}
+
+
+std::string Config_DataModelReader::
+ rootFolderFeatures(const std::string& theFolderName) const
+{
+ return getFolderFeatures(theFolderName, myRootFolderNames, myRootFeaturesList);
+}
+
/// \param theId id of the folder
CONFIG_EXPORT bool rootShowEmpty(int theId) const { return myRootFolderShowEmpty[theId]; }
+ /// Returns list of features attached to folder with name theFolderName in sub-document
+ /// \param theFolderName a name of the folder
+ CONFIG_EXPORT std::string rootFolderFeatures(const std::string& theFolderName) const;
// SUB folders propertiues ********************
/// \param theType type of objects in folder
CONFIG_EXPORT int subFolderId(std::string theType) const;
+ /// Returns list of features attached to folder with name theFolderName in sub-document
+ /// \param theFolderName a name of the folder
+ CONFIG_EXPORT std::string subFolderFeatures(const std::string& theFolderName) const;
+
+
/// Returns true if the sub-document data tree has to be attached to Part Result node
/// Otherwise it has to be connected to Part feature node
CONFIG_EXPORT bool isAttachToResult() const { return myIsResultLink; }
std::vector<std::string> myRootFolderNames;
std::vector<std::string> myRootFolderTypes;
std::vector<std::string> myRootFolderIcons;
+ std::vector<std::string> myRootFeaturesList;
std::vector<bool> myRootFolderShowEmpty;
std::string myRootTypes;
std::vector<std::string> mySubFolderNames;
std::vector<std::string> mySubFolderTypes;
std::vector<std::string> mySubFolderIcons;
+ std::vector<std::string> mySubFeaturesList;
std::vector<bool> mySubFolderShowEmpty;
bool myIsResultLink;
return myIsAutoPreview;
}
+bool Config_FeatureMessage::isModal() const
+{
+ return myModal;
+}
+
void Config_FeatureMessage::setUseInput(bool isUseInput)
{
myUseInput = isUseInput;
myInternal = isInternal;
}
+void Config_FeatureMessage::setModal(bool isModal)
+{
+ myModal = isModal;
+}
+
const std::string& Config_FeatureMessage::nestedFeatures() const
{
return myNestedFeatures;
\r
bool myUseInput; ///<Action is being checked until user commit the operation\r
bool myInternal; ///<Internal feature without GUI representation\r
+ bool myModal; ///<True if the feature has to be represented by modal dialog box\r
bool myIsAutoPreview; ///< Preview computation is performed automatically\r
\r
std::string myNestedFeatures; ///<Space separated list of child features\r
CONFIG_EXPORT bool isUseInput() const;\r
/// If true - feature will not be added into the workbench\r
CONFIG_EXPORT bool isInternal() const;\r
+ /// If true - the feature will be represented by modal dialog box GUI\r
+ CONFIG_EXPORT bool isModal() const;\r
\r
/// If true - preview of the feature is done by any modification of the feature attributes\r
CONFIG_EXPORT bool isAutoPreview() const;\r
CONFIG_EXPORT void setInternal(bool isInternal);\r
///Set auto preview state; If true - preview of the feature is computed automatically\r
CONFIG_EXPORT void setAutoPreview(bool isAutoPreview);\r
+ ///Set modality state; If true - the feature will be represented by modal dialog box GUI\r
+ CONFIG_EXPORT void setModal(bool isModal);\r
};\r
\r
#endif // CONFIG_MESSAGE_H\r
outFeatureMessage->setPluginLibrary(myLibraryName);
outFeatureMessage->setNestedFeatures(getProperty(theFeatureNode, FEATURE_NESTED));
outFeatureMessage->setActionsWhenNested(getNormalizedProperty(theFeatureNode, FEATURE_WHEN_NESTED));
+ outFeatureMessage->setModal(getBooleanAttribute(theFeatureNode, FEATURE_MODAL, false));
bool isInternal = getBooleanAttribute(theFeatureNode, ATTR_INTERNAL, false);
outFeatureMessage->setInternal(isInternal);
//Internal feature has no visual representation.
return;
}
+
outFeatureMessage->setText(getProperty(theFeatureNode, FEATURE_TEXT));
outFeatureMessage->setTooltip(getProperty(theFeatureNode, FEATURE_TOOLTIP));
outFeatureMessage->setIcon(getProperty(theFeatureNode, FEATURE_ICON));
const static char* FEATURE_WHEN_NESTED_ACCEPT = "accept";
const static char* FEATURE_WHEN_NESTED_ABORT = "abort";
const static char* FEATURE_DOC = WORKBENCH_DOC;
+const static char* FEATURE_MODAL = "modal";
const static char* FEATURE_AUTO_PREVIEW = "auto_preview";
// NODE_VALIDATOR properties, NODE_SELFILTER properties
const static char* _PARAMETERS = "parameters";
const static char* NODE_ICON = "icon";
const static char* SHOW_EMPTY = "show_empty";
const static char* LINK_ITEM = "from_result";
+const static char* FOLDER_FEATURES = "folder_features";
#endif /* CONFIG_KEYWORDS_H_ */
<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
<data_model>
<root_document group_type="Features">
- <folder name="Parameters" group_type="Parameters" icon=":pictures/params_folder.png"/>
+ <folder name="Parameters" group_type="Parameters" icon=":pictures/params_folder.png"
+ folder_features="ParametersMgr"/>
<folder name="Constructions" group_type="Construction" icon=":pictures/constr_folder.png"/>
<folder name="Parts" group_type="Parts" icon=":pictures/constr_folder.png"/>
</root_document>
<sub_document group_type="Features" from_result="false">
- <folder name="Parameters" group_type="Parameters" icon=":pictures/params_folder.png"/>
+ <folder name="Parameters" group_type="Parameters" icon=":pictures/params_folder.png"
+ folder_features="ParametersMgr"/>
<folder name="Constructions" group_type="Construction" icon=":pictures/constr_folder.png"/>
<folder name="Groups" group_type="Groups" icon=":pictures/constr_folder.png" show_empty="false"/>
<folder name="Bodies" group_type="Bodies" icon=":pictures/constr_folder.png"/>
}
// If feature requires PropertyPannel for input, it should be checkable
checkable = theMessage->isUseInput();
+ // If Feature requires modal Dialog box for input
+ modal = theMessage->isModal();
}
QAction* ModuleBase_ActionInfo::makeAction(QObject* theParent)
bool checked; //!< action's checked state
bool enabled; //!< action's enabled state
bool visible; //!< action's visibility state
+ bool modal; //!< = true if the acton is a modal dialog box else property panel (==false by default)
QIcon icon; //!< action's icon
QString text; //!< action's text
QString iconText; //!< action's descriptive icon text
INCLUDE(Common)
INCLUDE(FindPython)
INCLUDE(UnitTest)
+SET(CMAKE_AUTOMOC ON)
SET(PROJECT_HEADERS
ParametersPlugin.h
ParametersPlugin_PyInterp.h
ParametersPlugin_Validators.h
ParametersPlugin_EvalListener.h
+ ParametersPlugin_WidgetCreator.h
+ ParametersPlugin_ParametersMgr.h
+ ParametersPlugin_WidgetParamsMgr.h
)
SET(PROJECT_SOURCES
ParametersPlugin_PyInterp.cpp
ParametersPlugin_Validators.cpp
ParametersPlugin_EvalListener.cpp
+ ParametersPlugin_WidgetCreator.cpp
+ ParametersPlugin_ParametersMgr.cpp
+ ParametersPlugin_WidgetParamsMgr.cpp
)
SET(XML_RESOURCES
${PROJECT_SOURCE_DIR}/src/ModelAPI
${PROJECT_SOURCE_DIR}/src/GeomAPI
${PROJECT_SOURCE_DIR}/src/GeomDataAPI
+ ${PROJECT_SOURCE_DIR}/src/ModuleBase
${SUIT_INCLUDE}
${PYTHON_INCLUDE_DIR}
)
Events
Config
ModelAPI
+ ModuleBase
${PyInterp}
${PYTHON_LIBRARIES}
+ ${QT_LIBRARIES}
)
ADD_DEFINITIONS(-DPARAMETERSPLUGIN_EXPORTS -DHAVE_DEBUG_PYTHON)
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File: ParametersPlugin_ParametersMgr.cpp
+// Created: 07 April 2016
+// Author: vsv
+
+#include <pyconfig.h>
+
+#include "ParametersPlugin_ParametersMgr.h"
+
+
+ParametersPlugin_ParametersMgr::ParametersPlugin_ParametersMgr()
+ : ModelAPI_Feature()
+{
+}
+
+ParametersPlugin_ParametersMgr::~ParametersPlugin_ParametersMgr()
+{
+}
+
+void ParametersPlugin_ParametersMgr::initAttributes()
+{
+}
+
+void ParametersPlugin_ParametersMgr::execute()
+{
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File: ParametersPlugin_ParametersMgr.h
+// Created: 07 April 2016
+// Author: vsv
+
+#ifndef PARAMETERSPLUGIN_PARAMETERSMGR_H_
+#define PARAMETERSPLUGIN_PARAMETERSMGR_H_
+
+#include "ParametersPlugin.h"
+#include <ModelAPI_Feature.h>
+
+/**
+ * \class ParametersPlugin_ParametersMgr
+ * \ingroup Plugins
+ * \brief A macro feature which manages list of parameters in the current document.
+ */
+
+class ParametersPlugin_ParametersMgr : public ModelAPI_Feature
+{
+public:
+ /// Feature kind
+ inline static const std::string& ID()
+ {
+ static const std::string MY_PARAMSMGR_ID("ParametersMgr");
+ return MY_PARAMSMGR_ID;
+ }
+
+ /// Use plugin manager for features creation
+ ParametersPlugin_ParametersMgr();
+
+ /// Destructor
+ virtual ~ParametersPlugin_ParametersMgr();
+
+ /// Request for initialization of data model of the feature: adding all attributes
+ PARAMETERSPLUGIN_EXPORT virtual void initAttributes();
+
+ /// Returns the unique kind of a feature
+ PARAMETERSPLUGIN_EXPORT virtual const std::string& getKind()
+ {
+ static std::string MY_KIND = ParametersPlugin_ParametersMgr::ID();
+ return MY_KIND;
+ };
+
+ /// Computes or recomputes the results
+ PARAMETERSPLUGIN_EXPORT virtual void execute();
+
+ /// Reimplemented from ModelAPI_Feature::isMacro(). Returns true.
+ PARAMETERSPLUGIN_EXPORT virtual bool isMacro() const { return true; }
+
+ /// Reimplemented from ModelAPI_Feature::isPreviewNeeded(). Returns false.
+ PARAMETERSPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; }
+};
+
+
+#endif
\ No newline at end of file
#include <ParametersPlugin_Plugin.h>
#include <ParametersPlugin_Parameter.h>
+#include <ParametersPlugin_ParametersMgr.h>
#include <ParametersPlugin_Validators.h>
+#include <ParametersPlugin_WidgetCreator.h>
+
+#include <ModuleBase_WidgetCreatorFactory.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
ParametersPlugin_Plugin::ParametersPlugin_Plugin()
{
// register this plugin
+ WidgetCreatorFactoryPtr aWidgetCreatorFactory = ModuleBase_WidgetCreatorFactory::get();
+ aWidgetCreatorFactory->registerCreator(
+ std::shared_ptr<ParametersPlugin_WidgetCreator>(new ParametersPlugin_WidgetCreator()));
+
SessionPtr aSession = ModelAPI_Session::get();
aSession->registerPlugin(this);
if (theFeatureID == ParametersPlugin_Parameter::ID()) {
return FeaturePtr(new ParametersPlugin_Parameter);
}
+ if (theFeatureID == ParametersPlugin_ParametersMgr::ID()) {
+ return FeaturePtr(new ParametersPlugin_ParametersMgr);
+ }
return FeaturePtr();
}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ParametersPlugin_WidgetCreator.cpp
+// Created: 11 Apr 2016
+// Author: Vitaly SMETANNIKOV
+
+#include <ParametersPlugin_WidgetCreator.h>
+#include <ParametersPlugin_WidgetParamsMgr.h>
+
+
+ParametersPlugin_WidgetCreator::ParametersPlugin_WidgetCreator()
+ : ModuleBase_IWidgetCreator()
+{
+}
+
+
+void ParametersPlugin_WidgetCreator::widgetTypes(std::set<std::string>& theTypes)
+{
+ theTypes.clear();
+ theTypes.insert("parameters-manager");
+}
+
+
+ModuleBase_ModelWidget*
+ ParametersPlugin_WidgetCreator::createWidgetByType(const std::string& theType,
+ QWidget* theParent,
+ Config_WidgetAPI* theWidgetApi,
+ ModuleBase_IWorkshop* /*theWorkshop*/)
+{
+ ModuleBase_ModelWidget* aModelWidget = 0;
+ if (theType == "parameters-manager") {
+ aModelWidget = new ParametersPlugin_WidgetParamsMgr(theParent, theWidgetApi);
+ }
+ return aModelWidget;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ParametersPlugin_WidgetCreator.h
+// Created: 11 Apr 2016
+// Author: Vitaly SMETANNIKOV
+
+#ifndef ParametersPlugin_WidgetCreator_H
+#define ParametersPlugin_WidgetCreator_H
+
+#include "ParametersPlugin.h"
+
+#include <ModuleBase_IWidgetCreator.h>
+
+#include <string>
+#include <set>
+
+/**
+* \ingroup GUI
+* Interface to WidgetCreator which can create specific widgets by type
+*/
+class ParametersPlugin_WidgetCreator : public ModuleBase_IWidgetCreator
+{
+public:
+ /// Default constructor
+ ParametersPlugin_WidgetCreator();
+
+ /// Returns a container of possible widget types, which this creator can process
+ /// \param a list of type names
+ virtual void widgetTypes(std::set<std::string>& theTypes);
+
+ /// Create widget by its type
+ /// The default implementation is empty
+ /// \param theType a type
+ /// \param theParent a parent widget
+ /// \param theData a low-level API for reading xml definitions of widgets
+ /// \param theWorkshop a current workshop
+ /// \return a created model widget or null
+ virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
+ QWidget* theParent,
+ Config_WidgetAPI* theWidgetApi,
+ ModuleBase_IWorkshop* /*theWorkshop*/);
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File: ParametersPlugin_WidgetParamsMgr.cpp
+// Created: 11 Apr 2016
+// Author: Vitaly SMETANNIKOV
+
+#include "ParametersPlugin_WidgetParamsMgr.h"
+
+#include <QLayout>
+#include <QTreeWidget>
+#include <QPushButton>
+#include <QToolButton>
+
+ParametersPlugin_WidgetParamsMgr::ParametersPlugin_WidgetParamsMgr(QWidget* theParent, const Config_WidgetAPI* theData)
+ : ModuleBase_ModelWidget(theParent, theData)
+{
+ QVBoxLayout* aLayout = new QVBoxLayout(this);
+
+ myTable = new QTreeWidget(this);
+ myTable->setColumnCount(4);
+ QStringList aHeaders;
+ aHeaders << tr("Name") << tr("Equation") << tr("Result") << tr("Comment");
+ myTable->setHeaderLabels(aHeaders);
+ aLayout->addWidget(myTable);
+
+ QHBoxLayout* aBtnLayout = new QHBoxLayout(this);
+
+ QToolButton* aUpBtn = new QToolButton(this);
+ aUpBtn->setArrowType(Qt::DownArrow);
+ aBtnLayout->addWidget(aUpBtn);
+ QToolButton* aDownBtn = new QToolButton(this);
+ aDownBtn->setArrowType(Qt::UpArrow);
+ aBtnLayout->addWidget(aDownBtn);
+
+ aBtnLayout->addStretch();
+
+ QPushButton* aAddBtn = new QPushButton(tr("Add"), this);
+ aBtnLayout->addWidget(aAddBtn);
+ QPushButton* aInsertBtn = new QPushButton(tr("Insert"), this);
+ aBtnLayout->addWidget(aInsertBtn);
+ QPushButton* aRemoveBtn = new QPushButton(tr("Remove"), this);
+ aBtnLayout->addWidget(aRemoveBtn);
+
+ aLayout->addLayout(aBtnLayout);
+}
+
+QList<QWidget*> ParametersPlugin_WidgetParamsMgr::getControls() const
+{
+ QList<QWidget*> aList;
+
+ return aList;
+}
+
+bool ParametersPlugin_WidgetParamsMgr::storeValueCustom() const
+{
+ return true;
+}
+
+bool ParametersPlugin_WidgetParamsMgr::restoreValueCustom()
+{
+ return true;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File: ParametersPlugin_WidgetParamsMgr.h
+// Created: 11 Apr 2016
+// Author: Vitaly SMETANNIKOV
+
+#ifndef ParametersPlugin_WidgetParamsMgr_H_
+#define ParametersPlugin_WidgetParamsMgr_H_
+
+#include <ModuleBase_ModelWidget.h>
+
+class QTreeWidget;
+
+/*!
+ * \ingroup GUI
+ * Represent a content of the property panel to show/modify parameters of some feature.
+ */
+class ParametersPlugin_WidgetParamsMgr : public ModuleBase_ModelWidget
+{
+ Q_OBJECT
+public:
+ /// Constructs a model widget
+ ParametersPlugin_WidgetParamsMgr(QWidget* theParent, const Config_WidgetAPI* theData);
+
+ /// Destructs the model widget
+ virtual ~ParametersPlugin_WidgetParamsMgr() {}
+
+ /// Returns list of widget controls
+ /// \return a control list
+ virtual QList<QWidget*> getControls() const;
+
+protected:
+ /// Saves the internal parameters to the given feature
+ /// \return True in success
+ virtual bool storeValueCustom() const;
+
+ /// Restore value from attribute data to the widget's control
+ virtual bool restoreValueCustom();
+
+private:
+
+ QTreeWidget* myTable;
+};
+
+
+#endif
\ No newline at end of file
<plugin>
<workbench id="Part">
<group id="Parameters">
- <feature id="Parameter" title="Parameter" tooltip="Create a parameter" icon=":pictures/expression.png">
- <stringvalue id="variable" label="Name" icon=":pictures/expression.png" placeholder="Please input the parameter name">
+ <feature id="Parameter" title="Parameter" tooltip="Create a parameter" icon=":icons/expression.png">
+ <stringvalue id="variable" label="Name" icon=":icons/expression.png" placeholder="Please input the parameter name">
<validator id="Parameters_VariableValidator"/>
</stringvalue>
<expr_editor id="expression" placeholder="Please input the expression">
<validator id="Parameters_ExpressionValidator"/>
</expr_editor>
</feature>
+
+ <feature id="ParametersMgr" title="Parameters" tooltip="Manage parameters" icon=":icons/paper_roll.png" modal="true">
+ <parameters-manager/>
+ </feature>
</group>
</workbench>
</plugin>
<file>icons/hand_point.png</file>
<file>icons/move_to_end.png</file>
<file>icons/sketch_shape.png</file>
+ <file>icons/expression.png</file>
+ <file>icons/paper_roll.png</file>
</qresource>
</RCC>
#include "XGUI_DataModel.h"
#include "XGUI_OperationMgr.h"
#include "XGUI_Tools.h"
+#include "XGUI_ActionsMgr.h"
#ifndef HAVE_SALOME
#include <AppElements_MainWindow.h>
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_Tools.h>
+#include <Config_DataModelReader.h>
+
#include <ModuleBase_IModule.h>
#include <ModuleBase_Tools.h>
#include <ModuleBase_OperationAction.h>
#include <QMenu>
#include <QMdiArea>
#include <QMainWindow>
+#include <QModelIndex>
XGUI_ContextMenuMgr::XGUI_ContextMenuMgr(XGUI_Workshop* theParent)
aActions.append(action("DELETE_CMD"));
}
theMenu->addActions(aActions);
+ addFeatures(theMenu);
- theMenu->addSeparator();
- theMenu->addActions(myWorkshop->objectBrowser()->actions());
+ // It is commented out because Object Browser does not have actions
+ //theMenu->addSeparator();
+ //theMenu->addActions(myWorkshop->objectBrowser()->actions());
}
void XGUI_ContextMenuMgr::addViewerMenu(QMenu* theMenu) const
myWorkshop->objectBrowser()->setObjectsSelected(anObjects);
myWorkshop->objectBrowser()->onEditItem();
}
+
+void XGUI_ContextMenuMgr::addFeatures(QMenu* theMenu) const
+{
+ SessionPtr aMgr = ModelAPI_Session::get();
+ DocumentPtr aActiveDoc = aMgr->activeDocument();
+
+ XGUI_SelectionMgr* aSelMgr = myWorkshop->selector();
+ XGUI_ActionsMgr* aActionMgr = myWorkshop->actionsMgr();
+ const Config_DataModelReader* aDataModelXML = myWorkshop->dataModelXMLReader();
+ QModelIndexList aSelectedIndexes = aSelMgr->selection()->selectedIndexes();
+
+ QString aName;
+ int aLen = 0;
+ bool aIsRoot = false;
+ foreach(QModelIndex aIdx, aSelectedIndexes) {
+ // Process only first column
+ if (aIdx.column() == 0) {
+ aIsRoot = !aIdx.parent().isValid();
+ // Exit if the selected index belongs to non active document
+ if (aIsRoot && (aActiveDoc != aMgr->moduleDocument()))
+ return;
+ if ((!aIsRoot) && (aIdx.internalPointer() != aActiveDoc.get()))
+ return;
+
+ // Get name of the selected index
+ aName = aIdx.data().toString();
+ aLen = aName.indexOf('(');
+ if (aLen != -1) {
+ aName = aName.left(--aLen);
+ }
+ std::string aFeaturesStr = aIsRoot?
+ aDataModelXML->rootFolderFeatures(aName.toStdString()) :
+ aDataModelXML->subFolderFeatures(aName.toStdString());
+ if (aFeaturesStr.length() > 0) {
+ QStringList aFeturesList =
+ QString(aFeaturesStr.c_str()).split(",", QString::SkipEmptyParts);
+ foreach(QString aFea, aFeturesList) {
+ QAction* aAction = aActionMgr->action(aFea);
+ if (aAction)
+ theMenu->addAction(aAction);
+ }
+ }
+ }
+ }
+}
*/
void addAction(const QString& theId, QAction* theAction);
+ void addFeatures(QMenu* theMenu) const;
+
/// Updates menu for object browser
void updateObjectBrowserMenu();
#include <ModelAPI_Tools.h>
#include <Config_FeatureMessage.h>
+#include <Config_DataModelReader.h>
#include <Events_Loop.h>
#include <Events_Error.h>
// Constructor *************************************************
XGUI_DataModel::XGUI_DataModel(QObject* theParent) : QAbstractItemModel(theParent)
{
- myXMLReader.readAll();
-
Events_Loop* aLoop = Events_Loop::loop();
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_CREATED));
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED));
aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
}
+XGUI_DataModel::~XGUI_DataModel()
+{
+}
+
//******************************************************
void XGUI_DataModel::processEvent(const std::shared_ptr<Events_Message>& theMessage)
{
DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
- std::string aRootType = myXMLReader.rootType();
- std::string aSubType = myXMLReader.subType();
+ std::string aRootType = myXMLReader->rootType();
+ std::string aSubType = myXMLReader->subType();
int aNbFolders = foldersCount();
// Created object event *******************
foreach (QString aNotEmptyFolder, aNotEmptyFolders) {
if ((aNotEmptyFolder.toStdString() == aObjType) && (aRootDoc->size(aObjType) == 1))
// Appears first object in folder which can not be shown empty
- insertRow(myXMLReader.rootFolderId(aObjType));
+ insertRow(myXMLReader->rootFolderId(aObjType));
}
// Insert new object
int aRow = aRootDoc->size(aObjType) - 1;
if (aObjType == aRootType) {
insertRow(aRow + aNbFolders + 1);
} else {
- int aFolderId = myXMLReader.rootFolderId(aObjType);
+ int aFolderId = myXMLReader->rootFolderId(aObjType);
if (aFolderId != -1) {
insertRow(aRow, createIndex(aFolderId, 0, -1));
}
foreach (QString aNotEmptyFolder, aNotEmptyFolders) {
if ((aNotEmptyFolder.toStdString() == aObjType) && (aDoc->size(aObjType) == 1))
// Appears first object in folder which can not be shown empty
- insertRow(myXMLReader.subFolderId(aObjType), aDocRoot);
+ insertRow(myXMLReader->subFolderId(aObjType), aDocRoot);
}
int aRow = aDoc->index(aObject);
if (aRow != -1) {
rebuildBranch(aNbFolders, aRow);
} else {
// Process root sub-folder
- int aFolderId = myXMLReader.rootFolderId(aGroup);
+ int aFolderId = myXMLReader->rootFolderId(aGroup);
if (aFolderId != -1) {
QModelIndex aFolderIndex = createIndex(aFolderId, 0, -1);
removeRow(aRow, aFolderIndex);
foreach (QString aNotEmptyFolder, aNotEmptyFolders) {
if ((aNotEmptyFolder.toStdString() == aGroup) && (aRootDoc->size(aGroup) == 0)) {
// Appears first object in folder which can not be shown empty
- removeRow(myXMLReader.rootFolderId(aGroup));
- //rebuildBranch(0, aNbFolders + aDoc->size(myXMLReader.rootType()));
+ removeRow(myXMLReader->rootFolderId(aGroup));
+ //rebuildBranch(0, aNbFolders + aDoc->size(myXMLReader->rootType()));
break;
}
}
foreach (QString aNotEmptyFolder, aNotEmptyFolders) {
if ((aNotEmptyFolder.toStdString() == aGroup) && (aSize == 0)) {
// Appears first object in folder which can not be shown empty
- removeRow(myXMLReader.subFolderId(aGroup), aDocRoot);
- //rebuildBranch(0, aNbSubFolders + aDoc->size(myXMLReader.subType()), aDocRoot);
+ removeRow(myXMLReader->subFolderId(aGroup), aDocRoot);
+ //rebuildBranch(0, aNbSubFolders + aDoc->size(myXMLReader->subType()), aDocRoot);
break;
}
}
int aStartId = 0;
if (aDoc == aRootDoc) {
// Update a group under root
- if (aGroup == myXMLReader.rootType()) // Update objects under root
+ if (aGroup == myXMLReader->rootType()) // Update objects under root
aStartId = foldersCount();
else // Update objects in folder under root
aParent = createIndex(folderId(aGroup), 0, -1);
} else {
// Update a sub-document
- if (aGroup == myXMLReader.subType()) {
+ if (aGroup == myXMLReader->subType()) {
// Update sub-document root
aParent = findDocumentRootIndex(aDoc.get());
aStartId = foldersCount(aDoc.get());
}
SessionPtr aSession = ModelAPI_Session::get();
DocumentPtr aRootDoc = aSession->moduleDocument();
- if (aDoc == aRootDoc && myXMLReader.rootType() == aType) {
+ if (aDoc == aRootDoc && myXMLReader->rootType() == aType) {
// The object from root document
aRow += foldersCount();
- } else if (myXMLReader.subType() == aType) {
+ } else if (myXMLReader->subType() == aType) {
// The object from sub document
aRow += foldersCount(aDoc.get());
}
if (aParentId == -1) { // root folders
switch (theRole) {
case Qt::DisplayRole:
- return QString(myXMLReader.rootFolderName(theIndexRow).c_str()) +
+ return QString(myXMLReader->rootFolderName(theIndexRow).c_str()) +
QString(" (%1)").arg(rowCount(theIndex));
case Qt::DecorationRole:
- return ModuleBase_IconFactory::loadIcon(myXMLReader.rootFolderIcon(theIndexRow).c_str());
+ return QIcon(myXMLReader->rootFolderIcon(theIndexRow).c_str());
case Qt::ForegroundRole:
{
Qt::ItemFlags aFlags = theIndex.flags();
switch (theRole) {
case Qt::DisplayRole:
- return QString(myXMLReader.subFolderName(aRow).c_str()) +
+ return QString(myXMLReader->subFolderName(aRow).c_str()) +
QString(" (%1)").arg(rowCount(theIndex));
case Qt::DecorationRole:
- return ModuleBase_IconFactory::loadIcon(myXMLReader.subFolderIcon(aRow).c_str());
+ return QIcon(myXMLReader->subFolderIcon(aRow).c_str());
}
} else {
ModelAPI_Object* aObj = (ModelAPI_Object*)theIndex.internalPointer();
return aTitle + " = " + aVal;
}
QString aSuffix;
- if (aObj->groupName() == myXMLReader.subType()) {
+ if (aObj->groupName() == myXMLReader->subType()) {
ResultPartPtr aPartRes = getPartResult(aObj);
if (aPartRes.get()) {
if (aPartRes->partDoc().get() == NULL)
// Return number of items in root
int aNbFolders = foldersCount();
int aNbItems = 0;
- std::string aType = myXMLReader.rootType();
+ std::string aType = myXMLReader->rootType();
if (!aType.empty())
aNbItems = aRootDoc->size(aType);
return aNbFolders + aNbItems;
if (aId == -1) {
// this is a folder under root
int aParentPos = theParent.row();
- std::string aType = myXMLReader.rootFolderType(aParentPos);
+ std::string aType = myXMLReader->rootFolderType(aParentPos);
return aRootDoc->size(aType);
} else {
// It is an object which could have children
int aRow = theParent.row();
while (aMissedIdx.contains(aRow))
aRow++;
- std::string aType = myXMLReader.subFolderType(aRow);
+ std::string aType = myXMLReader->subFolderType(aRow);
return aDoc->size(aType);
} else {
ModelAPI_Object* aObj = (ModelAPI_Object*)theParent.internalPointer();
int aNbSubFolders = foldersCount(aSubDoc.get());
int aNbSubItems = 0;
- std::string aSubType = myXMLReader.subType();
+ std::string aSubType = myXMLReader->subType();
if (!aSubType.empty())
aNbSubItems = aSubDoc->size(aSubType);
return aNbSubItems + aNbSubFolders;
if (theRow < aNbFolders) // Return first level folder index
return createIndex(theRow, theColumn, -1);
else { // return object under root index
- std::string aType = myXMLReader.rootType();
+ std::string aType = myXMLReader->rootType();
int aObjId = theRow - aNbFolders;
if (aObjId < aRootDoc->size(aType)) {
ObjectPtr aObj = aRootDoc->object(aType, aObjId);
int aId = theParent.internalId();
int aParentPos = theParent.row();
if (aId == -1) { // return object index inside of first level of folders
- std::string aType = myXMLReader.rootFolderType(aParentPos);
+ std::string aType = myXMLReader->rootFolderType(aParentPos);
if (theRow < aRootDoc->size(aType)) {
ObjectPtr aObj = aRootDoc->object(aType, theRow);
aIndex = objectIndex(aObj);
QIntList aMissedIdx = missedFolderIndexes(aDoc);
while (aMissedIdx.contains(aParentRow))
aParentRow++;
- std::string aType = myXMLReader.subFolderType(aParentRow);
+ std::string aType = myXMLReader->subFolderType(aParentRow);
if (theRow < aDoc->size(aType)) {
ObjectPtr aObj = aDoc->object(aType, theRow);
aIndex = objectIndex(aObj);
aIndex = createIndex(theRow, theColumn, aSubDoc.get());
} else {
// this is an object under sub document root
- std::string aType = myXMLReader.subType();
+ std::string aType = myXMLReader->subType();
ObjectPtr aObj = aSubDoc->object(aType, theRow - aNbSubFolders);
aIndex = objectIndex(aObj);
}
DocumentPtr aRootDoc = aSession->moduleDocument();
DocumentPtr aSubDoc = aObj->document();
if (aSubDoc == aRootDoc) {
- if (aType == myXMLReader.rootType())
+ if (aType == myXMLReader->rootType())
return QModelIndex();
else {
// return first level of folder index
- int aFolderId = myXMLReader.rootFolderId(aType);
+ int aFolderId = myXMLReader->rootFolderId(aType);
// Items in a one row must have the same parent
return createIndex(aFolderId, 0, -1);
}
} else {
- if (aType == myXMLReader.subType())
+ if (aType == myXMLReader->subType())
return findDocumentRootIndex(aSubDoc.get());
else {
// return first level of folder index
- int aFolderId = myXMLReader.subFolderId(aType);
+ int aFolderId = myXMLReader->subFolderId(aType);
// Items in a one row must have the same parent
return createIndex(aFolderId, 0, aSubDoc.get());
}
{
SessionPtr aSession = ModelAPI_Session::get();
DocumentPtr aRootDoc = aSession->moduleDocument();
- if (myXMLReader.isAttachToResult()) { // If document is attached to result
+ if (myXMLReader->isAttachToResult()) { // If document is attached to result
int aNb = aRootDoc->size(ModelAPI_ResultPart::group());
ObjectPtr aObj;
ResultPartPtr aPartRes;
aPartRes = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aObj);
if (aPartRes.get() && (aPartRes->partDoc().get() == theDoc)) {
int aRow = i;
- if (myXMLReader.rootType() == ModelAPI_Feature::group()) {
+ if (myXMLReader->rootType() == ModelAPI_Feature::group()) {
aRow += foldersCount();
}
return createIndex(aRow, 0, aObj.get());
aPartRes = getPartResult(aObj.get());
if (aPartRes.get() && (aPartRes->partDoc().get() == theDoc)) {
int aRow = i;
- if (myXMLReader.rootType() == ModelAPI_Feature::group())
+ if (myXMLReader->rootType() == ModelAPI_Feature::group())
aRow += foldersCount();
return createIndex(aRow, 0, aObj.get());
}
SessionPtr aSession = ModelAPI_Session::get();
DocumentPtr aRootDoc = aSession->moduleDocument();
if ((theDoc == 0) || (theDoc == aRootDoc.get())) {
- for (int i = 0; i < myXMLReader.rootFoldersNumber(); i++) {
- if (myXMLReader.rootShowEmpty(i))
+ for (int i = 0; i < myXMLReader->rootFoldersNumber(); i++) {
+ if (myXMLReader->rootShowEmpty(i))
aNb++;
else {
- if (aRootDoc->size(myXMLReader.rootFolderType(i)) > 0)
+ if (aRootDoc->size(myXMLReader->rootFolderType(i)) > 0)
aNb++;
}
}
} else {
- for (int i = 0; i < myXMLReader.subFoldersNumber(); i++) {
- if (myXMLReader.subShowEmpty(i))
+ for (int i = 0; i < myXMLReader->subFoldersNumber(); i++) {
+ if (myXMLReader->subShowEmpty(i))
aNb++;
else {
- if (theDoc->size(myXMLReader.subFolderType(i)) > 0)
+ if (theDoc->size(myXMLReader->subFolderType(i)) > 0)
aNb++;
}
}
SessionPtr aSession = ModelAPI_Session::get();
DocumentPtr aRootDoc = aSession->moduleDocument();
if ((theDoc == 0) || (theDoc == aRootDoc.get())) {
- for (int i = 0; i < myXMLReader.rootFoldersNumber(); i++) {
- if (!myXMLReader.rootShowEmpty(i)) {
- if (aRootDoc->size(myXMLReader.rootFolderType(i)) == 0)
+ for (int i = 0; i < myXMLReader->rootFoldersNumber(); i++) {
+ if (!myXMLReader->rootShowEmpty(i)) {
+ if (aRootDoc->size(myXMLReader->rootFolderType(i)) == 0)
aList.append(i);
}
}
} else {
- for (int i = 0; i < myXMLReader.subFoldersNumber(); i++) {
- if (!myXMLReader.subShowEmpty(i)) {
- if (theDoc->size(myXMLReader.subFolderType(i)) == 0)
+ for (int i = 0; i < myXMLReader->subFoldersNumber(); i++) {
+ if (!myXMLReader->subShowEmpty(i)) {
+ if (theDoc->size(myXMLReader->subFolderType(i)) == 0)
aList.append(i);
}
}
{
QStringList aResult;
if (fromRoot) {
- for (int i = 0; i < myXMLReader.rootFoldersNumber(); i++) {
- if (!myXMLReader.rootShowEmpty(i))
- aResult << myXMLReader.rootFolderType(i).c_str();
+ for (int i = 0; i < myXMLReader->rootFoldersNumber(); i++) {
+ if (!myXMLReader->rootShowEmpty(i))
+ aResult << myXMLReader->rootFolderType(i).c_str();
}
} else {
- for (int i = 0; i < myXMLReader.subFoldersNumber(); i++) {
- if (!myXMLReader.subShowEmpty(i))
- aResult << myXMLReader.subFolderType(i).c_str();
+ for (int i = 0; i < myXMLReader->subFoldersNumber(); i++) {
+ if (!myXMLReader->subShowEmpty(i))
+ aResult << myXMLReader->subFolderType(i).c_str();
}
}
return aResult;
int aRes = -1;
if (aUseSubDoc) {
- int aId = myXMLReader.subFolderId(theType);
+ int aId = myXMLReader->subFolderId(theType);
aRes = aId;
for (int i = 0; i < aId; i++) {
- if (!myXMLReader.subShowEmpty(i)) {
- if (aDoc->size(myXMLReader.subFolderType(i)) == 0)
+ if (!myXMLReader->subShowEmpty(i)) {
+ if (aDoc->size(myXMLReader->subFolderType(i)) == 0)
aRes--;
}
}
} else {
- int aId = myXMLReader.rootFolderId(theType);
+ int aId = myXMLReader->rootFolderId(theType);
aRes = aId;
for (int i = 0; i < aId; i++) {
- if (!myXMLReader.rootShowEmpty(i)) {
- if (aDoc->size(myXMLReader.rootFolderType(i)) == 0)
+ if (!myXMLReader->rootShowEmpty(i)) {
+ if (aDoc->size(myXMLReader->rootFolderType(i)) == 0)
aRes--;
}
}
#include <ModuleBase_Definitions.h>
#include <ModelAPI_Object.h>
#include <ModelAPI_Document.h>
-#include <Config_DataModelReader.h>
#include <Events_Listener.h>
#include <QAbstractItemModel>
+class Config_DataModelReader;
+
/**\class XGUI_DataModel
* \ingroup GUI
* \brief This is a data model for Object Browser (QTreeView).
/// \param theParent a parent object
XGUI_DataModel(QObject* theParent);
+ /// Destructor
+ virtual ~XGUI_DataModel();
+
/// Event Listener method
/// \param theMessage an event message
virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
/// Returns last history object index
virtual QModelIndex lastHistoryIndex() const;
+ /// Initialises XML data model reader. It must be initialised before DataModel using.
+ void setXMLReader(Config_DataModelReader* theReader) { myXMLReader = theReader; }
+
private:
/// Find a root index which contains objects of the given document
/// \param theDoc the document object
/// \param fromRoot - root document flag
QStringList listOfShowNotEmptyFolders(bool fromRoot = true) const;
- Config_DataModelReader myXMLReader;
+ Config_DataModelReader* myXMLReader;
};
#endif
\ No newline at end of file
aLabelWgt->setPalette(aPalet);
myDocModel = new XGUI_DataModel(this);
- myTreeView->setModel(myDocModel);
-
- // It has to be done after setting of model
- myActiveDocLbl->setTreeView(myTreeView);
QItemSelectionModel* aSelMod = myTreeView->selectionModel();
connect(aSelMod, SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
{
}
+void XGUI_ObjectsBrowser::setXMLReader(Config_DataModelReader* theReader)
+{
+ myDocModel->setXMLReader(theReader);
+ myTreeView->setModel(myDocModel);
+
+ // It has to be done after setting of model
+ myActiveDocLbl->setTreeView(myTreeView);
+}
//***************************************************
void XGUI_ObjectsBrowser::onContextMenuRequested(QContextMenuEvent* theEvent)
class ModuleBase_IDocumentDataModel;
class XGUI_DataModel;
+class Config_DataModelReader;
/**
* \ingroup GUI
/// Resets the object browser into initial state
void clearContent();
+ void setXMLReader(Config_DataModelReader* theReader);
+
public slots:
//! Called on Edit command request
void onEditItem();
#include <Config_PointerMessage.h>
#include <Config_PropManager.h>
#include <Config_SelectionFilterMessage.h>
+#include <Config_DataModelReader.h>
#include <SUIT_ResourceMgr.h>
QLocale::setDefault( QLocale::system() );
#endif
+ myDataModelXMLReader = new Config_DataModelReader();
+ myDataModelXMLReader->readAll();
+
myDisplayer = new XGUI_Displayer(this);
mySelector = new XGUI_SelectionMgr(this);
XGUI_Workshop::~XGUI_Workshop(void)
{
delete myDisplayer;
+ delete myDataModelXMLReader;
}
//******************************************************
aObjDock->setStyleSheet(
"::title { position: relative; padding-left: 5px; text-align: left center }");
myObjectBrowser = new XGUI_ObjectsBrowser(aObjDock);
+ myObjectBrowser->setXMLReader(myDataModelXMLReader);
myModule->customizeObjectBrowser(myObjectBrowser);
aObjDock->setWidget(myObjectBrowser);
class QMainWindow;
class QAction;
-
+class Config_DataModelReader;
/**\class XGUI_Workshop
* \ingroup GUI
/// features found in the given list
void highlightResults(const QObjectPtrList& theObjects);
+ /// Returns Data Model XML reader which contains information about
+ /// Data structure configuration
+ const Config_DataModelReader* dataModelXMLReader() const { return myDataModelXMLReader; }
+
/// A constant string used for "Move to end" command definition
/// It is used for specific processing of Undo/Redo for this command.
static QString MOVE_TO_END_COMMAND;
QString myCurrentDir;
int myViewerSelMode;
+
+ Config_DataModelReader* myDataModelXMLReader;
};
#endif
<file>pictures/module.png</file>
<file>pictures/shading.png</file>
<file>pictures/wireframe.png</file>
- <file>pictures/expression.png</file>
<file>pictures/arrow.png</file>
<file>pictures/solid.png</file>