${PROJECT_SOURCE_DIR}/src/PyInterp
${PROJECT_SOURCE_DIR}/src/PyConsole
${PROJECT_SOURCE_DIR}/src/ModelAPI
+ ${PROJECT_SOURCE_DIR}/src/Model
+ ${PROJECT_SOURCE_DIR}/src/ModuleBase
${CAS_INCLUDE_DIRS})
LINK_DIRECTORIES($ENV{PYTHON_LIB_DIR})
XGUI_DocumentDataModel::~XGUI_DocumentDataModel()
{
++ clearModelIndexes();
}
-QVariant XGUI_DocumentDataModel::data(const QModelIndex& theIndex, int theRole) const
+void XGUI_DocumentDataModel::processEvent(const Event_Message* theMessage)
{
- switch (theRole) {
- case Qt::DisplayRole:
- // return a name
- if (theIndex.internalId() == quintptr(&myParamsFolder))
- return "Parameters";
- else if (theIndex.internalId() == quintptr(&myConstructFolder))
- return "Constructions";
- else if (theIndex.internalId() == 0) {
- return "Part";
+ beginResetModel();
+ int aNbParts = myDocument->featuresIterator(PARTS_GROUP)->numIterationsLeft();
+ if (myPartModels.size() != aNbParts) { // resize internal models
+ while (myPartModels.size() > aNbParts) {
+ delete myPartModels.last();
+ myPartModels.removeLast();
}
- break;
- case Qt::DecorationRole:
- // return an Icon
- break;
- case Qt::ToolTipRole:
- // return Tooltip
- break;
+ while (myPartModels.size() < aNbParts) {
+ myPartModels.append(new XGUI_PartDataModel(this));
+ }
+ for (int i = 0; i < myPartModels.size(); i++)
+ myPartModels.at(i)->setDocument(myDocument, i);
}
- return QVariant();
++ clearModelIndexes();
+ endResetModel();
+}
+
+QVariant XGUI_DocumentDataModel::data(const QModelIndex& theIndex, int theRole) const
+{
+ if (!theIndex.isValid())
+ return QVariant();
+ return toSourceModel(theIndex).data(theRole);
}
return QVariant();
}
-int XGUI_DocumentDataModel::rowCount(const QModelIndex &parent) const
+int XGUI_DocumentDataModel::rowCount(const QModelIndex& theParent) const
{
- std::shared_ptr<ModelAPI_Iterator> aIt = myDocument->featuresIterator(PARTS_GROUP);
- return aIt->numIterationsLeft() + 2;
+ if (!theParent.isValid())
+ return myModel->rowCount(theParent) + myPartModels.size();
+
- return 0;
++ QModelIndex aParent = toSourceModel(theParent);
++ return aParent.model()->rowCount(aParent);
}
-int XGUI_DocumentDataModel::columnCount(const QModelIndex &parent) const
+int XGUI_DocumentDataModel::columnCount(const QModelIndex& theParent) const
{
return 1;
}
QModelIndex XGUI_DocumentDataModel::index(int theRow, int theColumn, const QModelIndex& theParent) const
{
- switch (theRow) {
- case 0:
- return createIndex(theRow, theColumn, (quintptr) &myParamsFolder);
- case 1:
- return createIndex(theRow, theColumn, (quintptr) &myConstructFolder);
- default:
- {
- std::shared_ptr<ModelAPI_Iterator> aIt = myDocument->featuresIterator(PARTS_GROUP);
- if (aIt->numIterationsLeft() <= (theRow - 1)) {
- return createIndex(theRow, theColumn, (quintptr) 0);
- }
- }
+ QModelIndex aIndex;
+ if (!theParent.isValid()) {
+ int aOffs = myModel->rowCount();
+ if (theRow < aOffs)
+ aIndex = myModel->index(theRow, theColumn, theParent);
+ else
+ aIndex = myPartModels.at(theRow - aOffs)->index(theRow - aOffs, theColumn, theParent);
- aIndex = createIndex(theRow, theColumn, aIndex.internalId());
++
++ aIndex = createIndex(theRow, theColumn, (void*)getModelIndex(aIndex));
++ } else {
++ QModelIndex* aParent = (QModelIndex*)theParent.internalPointer();
++ aIndex = aParent->model()->index(theRow, theColumn, (*aParent));
++
++ aIndex = createIndex(theRow, theColumn, (void*)getModelIndex(aIndex));
}
- return QModelIndex();
+ return aIndex;
}
-QModelIndex XGUI_DocumentDataModel::parent(const QModelIndex &index) const
+QModelIndex XGUI_DocumentDataModel::parent(const QModelIndex& theIndex) const
{
-- return QModelIndex();
++ QModelIndex aParent = toSourceModel(theIndex);
++ aParent = aParent.model()->parent(aParent);
++ if (aParent.isValid())
++ return createIndex(aParent.row(), aParent.column(), (void*)getModelIndex(aParent));
++ return aParent;
}
+
bool XGUI_DocumentDataModel::hasChildren(const QModelIndex& theParent) const
{
if (!theParent.isValid())
return true;
- return false;
++ return rowCount(theParent) > 0;
+}
- if (theParent.internalId() == quintptr(&myParamsFolder))
- return myDocument->featuresIterator(PARAMETERS_GROUP)->more();
- if (theParent.internalId() == quintptr(&myConstructFolder))
- return myDocument->featuresIterator(CONSTRUCTIONS_GROUP)->more();
- if (theParent.internalId() == 0)
- return false;
- return false;
+
+QModelIndex XGUI_DocumentDataModel::toSourceModel(const QModelIndex& theProxy) const
+{
- int aRow = theProxy.row();
- if (!theProxy.parent().isValid()) {
- if (aRow < myModel->rowCount()) {
- return myModel->index(aRow, 0);
- } else {
- int aOffs = aRow - myModel->rowCount();
- return myPartModels.at(aOffs)->index(aOffs, 0);
- }
- }
- return QModelIndex();
++ QModelIndex* aIndexPtr = static_cast<QModelIndex*>(theProxy.internalPointer());
++ return (*aIndexPtr);
++}
++
++
++QModelIndex* XGUI_DocumentDataModel::findModelIndex(const QModelIndex& theIndex) const
++{
++ QList<QModelIndex*>::const_iterator aIt;
++ for (aIt = myIndexes.constBegin(); aIt != myIndexes.constEnd(); ++aIt) {
++ QModelIndex* aIndex = (*aIt);
++ if ((*aIndex) == theIndex)
++ return aIndex;
++ }
++ return 0;
+}
+
++QModelIndex* XGUI_DocumentDataModel::getModelIndex(const QModelIndex& theIndex) const
++{
++ QModelIndex* aIndexPtr = findModelIndex(theIndex);
++ if (!aIndexPtr) {
++ aIndexPtr = new QModelIndex(theIndex);
++ XGUI_DocumentDataModel* that = (XGUI_DocumentDataModel*) this;
++ that->myIndexes.append(aIndexPtr);
++ }
++ return aIndexPtr;
++}
+
++void XGUI_DocumentDataModel::clearModelIndexes()
++{
++ QList<QModelIndex*>::const_iterator aIt;
++ for (aIt = myIndexes.constBegin(); aIt != myIndexes.constEnd(); ++aIt)
++ delete (*aIt);
++ myIndexes.clear();
+ }
virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
private:
- //std::shared_ptr<ModelAPI_Feature> myRoot;
- short myParamsFolder;
- short myConstructFolder;
+
+ QModelIndex toSourceModel(const QModelIndex& theProxy) const;
- QModelIndex fromSourceModel(const QModelIndex& theSource) const;
-
++ QModelIndex* findModelIndex(const QModelIndex& theIndex) const;
++ QModelIndex* getModelIndex(const QModelIndex& theIndex) const;
++ void clearModelIndexes();
std::shared_ptr<ModelAPI_Document> myDocument;
+
+ XGUI_TopDataModel* myModel;
+ QList<XGUI_PartDataModel*> myPartModels;
++
++ QList<QModelIndex*> myIndexes;
};
#endif
--- /dev/null
- if (theIndex.model() == this) {
- if (theIndex.internalId() == ParamsFolder)
- return tr("Parameters");
-
- if (theIndex.internalId() == ParamObject) {
+#include "XGUI_PartDataModel.h"
+
+#include <ModelAPI_PluginManager.h>
+#include <ModelAPI_Iterator.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_AttributeDocRef.h>
+
+#include <QIcon>
+
+XGUI_TopDataModel::XGUI_TopDataModel(QObject* theParent)
+ : QAbstractItemModel(theParent)
+{
+}
+
+XGUI_TopDataModel::~XGUI_TopDataModel()
+{
+}
+
+
+QVariant XGUI_TopDataModel::data(const QModelIndex& theIndex, int theRole) const
+{
+ switch (theRole) {
+ case Qt::DisplayRole:
+ // return a name
- if (theIndex.internalId() == ConstructFolder)
++ switch (theIndex.internalId()) {
++ case ParamsFolder:
++ return tr("Parameters");
++ case ParamObject:
++ {
+ std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARAMETERS_GROUP, theIndex.row());
+ return aFeature->data()->getName().c_str();
+ }
-
- if (theIndex.internalId() == ConstructObject) {
++ case ConstructFolder:
+ return tr("Constructions");
- }
++ case ConstructObject:
++ {
+ std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row());
+ return aFeature->data()->getName().c_str();
+ }
- if (theIndex.model() == this) {
- if (theIndex.internalId() == ParamsFolder)
++ }
+ break;
+
+ case Qt::DecorationRole:
+ // return an Icon
- else if (theIndex.internalId() == ConstructFolder)
++ switch (theIndex.internalId()) {
++ case ParamsFolder:
+ return QIcon(":pictures/params_folder.png");
- if (!theParent.isValid())
- return true;
-
- int aId = (int)theParent.internalId();
- switch (aId) {
- case ParamsFolder:
- return myDocument->featuresIterator(PARAMETERS_GROUP)->more();
- case ConstructFolder:
- return myDocument->featuresIterator(CONSTRUCTIONS_GROUP)->more();
- case ParamObject:
- case ConstructObject:
- return false;
- }
- return false;
++ case ConstructFolder:
+ return QIcon(":pictures/constr_folder.png");
++ case ConstructObject:
++ return QIcon(":pictures/point_ico.png");
+ }
+ break;
+
+ case Qt::ToolTipRole:
+ // return Tooltip
+ break;
+ }
+ return QVariant();
+}
+
+QVariant XGUI_TopDataModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ return QVariant();
+}
+
+int XGUI_TopDataModel::rowCount(const QModelIndex& theParent) const
+{
+ if (!theParent.isValid())
+ return 2;
+
+ if (theParent.internalId() == ParamsFolder)
+ return myDocument->featuresIterator(PARAMETERS_GROUP)->numIterationsLeft();
+
+ if (theParent.internalId() == ConstructFolder)
+ return myDocument->featuresIterator(CONSTRUCTIONS_GROUP)->numIterationsLeft();
+
+ return 0;
+}
+
+int XGUI_TopDataModel::columnCount(const QModelIndex &parent) const
+{
+ return 1;
+}
+
+QModelIndex XGUI_TopDataModel::index(int theRow, int theColumn, const QModelIndex& theParent) const
+{
+ if (!theParent.isValid()) {
+ switch (theRow) {
+ case 0:
+ return createIndex(theRow, theColumn, (quintptr) ParamsFolder);
+ case 1:
+ return createIndex(theRow, theColumn, (quintptr) ConstructFolder);
+ }
+ } else {
+ if (theParent.internalId() == ParamsFolder)
+ return createIndex(theRow, theColumn, (quintptr) ParamObject);
+
+ if (theParent.internalId() == ConstructFolder)
+ return createIndex(theRow, theColumn, (quintptr) ConstructObject);
+ }
+ return QModelIndex();
+}
+
+QModelIndex XGUI_TopDataModel::parent(const QModelIndex& theIndex) const
+{
+ int aId = (int)theIndex.internalId();
+ switch (aId) {
+ case ParamsFolder:
+ case ConstructFolder:
+ return QModelIndex();
+ case ParamObject:
+ return createIndex(0, 0, (quintptr) ParamsFolder);
+ case ConstructObject:
+ return createIndex(1, 0, (quintptr) ConstructFolder);
+ }
+ return QModelIndex();
+}
+
+bool XGUI_TopDataModel::hasChildren(const QModelIndex& theParent) const
+{
- if (theIndex.internalId() == MyRoot) {
- std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARTS_GROUP, myId);
- return aFeature->data()->getName().c_str();
- }
- if (theIndex.internalId() == ParamsFolder)
++ return rowCount(theParent) > 0;
+}
+
+
+//******************************************************************
+//******************************************************************
+//******************************************************************
+XGUI_PartDataModel::XGUI_PartDataModel(QObject* theParent)
+ : QAbstractItemModel(theParent)
+{
+}
+
+
+XGUI_PartDataModel::~XGUI_PartDataModel()
+{
+}
+
+QVariant XGUI_PartDataModel::data(const QModelIndex& theIndex, int theRole) const
+{
+ switch (theRole) {
+ case Qt::DisplayRole:
+ // return a name
- if (theIndex.internalId() == ConstructFolder)
++ switch (theIndex.internalId()) {
++ case MyRoot:
++ {
++ std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARTS_GROUP, myId);
++ return aFeature->data()->getName().c_str();
++ }
++ case ParamsFolder:
+ return tr("Parameters");
- if (theIndex.internalId() == MyRoot)
++ case ConstructFolder:
+ return tr("Constructions");
++ case ParamObject:
++ {
++ std::shared_ptr<ModelAPI_Feature> aFeature =
++ featureDocument()->feature(PARAMETERS_GROUP, theIndex.row());
++ return aFeature->data()->getName().c_str();
++ }
++ case ConstructObject:
++ {
++ std::shared_ptr<ModelAPI_Feature> aFeature =
++ featureDocument()->feature(CONSTRUCTIONS_GROUP, theIndex.row());
++ return aFeature->data()->getName().c_str();
++ }
++ }
+ break;
+ case Qt::DecorationRole:
+ // return an Icon
- if (theIndex.internalId() == ParamsFolder)
++ switch (theIndex.internalId()) {
++ case MyRoot:
+ return QIcon(":pictures/part_ico.png");
- if (theIndex.internalId() == ConstructFolder)
++ case ParamsFolder:
+ return QIcon(":pictures/params_folder.png");
- if (parent.internalId() == MyRoot)
- return 2;
++ case ConstructFolder:
+ return QIcon(":pictures/constr_folder.png");
++ case ConstructObject:
++ return QIcon(":pictures/point_ico.png");
++ }
+ break;
+ case Qt::ToolTipRole:
+ // return Tooltip
+ break;
+ }
+ return QVariant();
+}
+
+QVariant XGUI_PartDataModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ return QVariant();
+}
+
+int XGUI_PartDataModel::rowCount(const QModelIndex& parent) const
+{
+ if (!parent.isValid())
+ if (myDocument->feature(PARTS_GROUP, myId))
+ return 1;
+ else
+ return 0;
- if (!theParent.isValid())
- return myDocument->feature(PARTS_GROUP, myId);
-
- int aId = (int)theParent.internalId();
- switch (aId) {
- case MyRoot:
- return true;
- case ParamsFolder:
- return false; // TODO
- case ConstructFolder:
- return false; // TODO
- case ParamObject:
- case ConstructObject:
- return false;
- }
- return false;
++ switch (parent.internalId()) {
++ case MyRoot:
++ return 2;
++ case ParamsFolder:
++ return featureDocument()->featuresIterator(PARAMETERS_GROUP)->numIterationsLeft();
++ case ConstructFolder:
++ return featureDocument()->featuresIterator(CONSTRUCTIONS_GROUP)->numIterationsLeft();
++ }
+ return 0;
+}
+
+int XGUI_PartDataModel::columnCount(const QModelIndex &parent) const
+{
+ return 1;
+}
+
+QModelIndex XGUI_PartDataModel::index(int theRow, int theColumn, const QModelIndex &theParent) const
+{
+ if (!theParent.isValid())
+ return createIndex(theRow, 0, (quintptr) MyRoot);
+
+ int aId = (int)theParent.internalId();
+ switch (aId) {
+ case MyRoot:
+ switch (theRow) {
+ case 0:
+ return createIndex(0, 0, (quintptr) ParamsFolder);
+ case 1:
+ return createIndex(1, 0, (quintptr) ConstructFolder);
+ }
+ case ParamsFolder:
+ return createIndex(theRow, 0, (quintptr) ParamObject);
+ case ConstructFolder:
+ return createIndex(theRow, 0, (quintptr) ConstructObject);
+ }
+ return QModelIndex();
+}
+
+QModelIndex XGUI_PartDataModel::parent(const QModelIndex& theIndex) const
+{
+ int aId = (int)theIndex.internalId();
+ switch (aId) {
+ case MyRoot:
+ return QModelIndex();
+ case ParamsFolder:
+ case ConstructFolder:
+ return createIndex(0, 0, (quintptr) MyRoot);
+ case ParamObject:
+ return createIndex(0, 0, (quintptr) ParamsFolder);
+ case ConstructObject:
+ return createIndex(1, 0, (quintptr) ConstructFolder);
+ }
+ return QModelIndex();
+}
+
+bool XGUI_PartDataModel::hasChildren(const QModelIndex& theParent) const
+{
++ return rowCount(theParent) > 0;
+}
++
++
++std::shared_ptr<ModelAPI_Document> XGUI_PartDataModel::featureDocument() const
++{
++ std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARTS_GROUP, myId);
++ return aFeature->data()->docRef("PartDocument")->value();
++}
--- /dev/null
+
+#ifndef XGUI_PartDataModel_H
+#define XGUI_PartDataModel_H
+
+#include <QAbstractItemModel>
+
+class ModelAPI_Feature;
+class ModelAPI_Document;
+
+class XGUI_TopDataModel : public QAbstractItemModel
+{
+ Q_OBJECT
+public:
+ XGUI_TopDataModel(QObject* theParent);
+ virtual ~XGUI_TopDataModel();
+
+ virtual void setDocument(const std::shared_ptr<ModelAPI_Document>& theDoc)
+ {
+ myDocument = theDoc;
+ }
+
+ // Reimplementation from QAbstractItemModel
+ virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
+ virtual QVariant headerData(int section, Qt::Orientation orientation,
+ int role = Qt::DisplayRole) const;
+
+ virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
+
+ virtual QModelIndex index(int theRow, int theColumn,
+ const QModelIndex& theParent = QModelIndex()) const;
+
+ virtual QModelIndex parent(const QModelIndex& theIndex) const;
+
+ virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
+
+private:
+ enum DataIds {
+ ParamsFolder,
+ ParamObject,
+ ConstructFolder,
+ ConstructObject
+ };
+
+ std::shared_ptr<ModelAPI_Document> myDocument;
+};
+
+
+
+class XGUI_PartDataModel : public QAbstractItemModel
+{
+ Q_OBJECT
+public:
+ XGUI_PartDataModel(QObject* theParent);
+ virtual ~XGUI_PartDataModel();
+
+ virtual void setDocument(const std::shared_ptr<ModelAPI_Document>& theDoc, int theId)
+ {
+ myDocument = theDoc;
+ myId = theId;
+ }
+
+ // Reimplementation from QAbstractItemModel
+ virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
+ virtual QVariant headerData(int section, Qt::Orientation orientation,
+ int role = Qt::DisplayRole) const;
+
+ virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
+
+ virtual QModelIndex index(int theRow, int theColumn,
+ const QModelIndex& theParent = QModelIndex()) const;
+
+ virtual QModelIndex parent(const QModelIndex& theIndex) const;
+
+ virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
+
+private:
++ std::shared_ptr<ModelAPI_Document> featureDocument() const;
++
++
+ enum DataIds {
+ MyRoot,
+ ParamsFolder,
+ ParamObject,
+ ConstructFolder,
+ ConstructObject
+ };
+
+ std::shared_ptr<ModelAPI_Document> myDocument;
+ int myId;
+};
+
+#endif
#include "XGUI_Viewer.h"
#include "XGUI_WidgetFactory.h"
+#include <ModelAPI_PluginManager.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_AttributeDocRef.h>
+
#include <Event_Loop.h>
+ #include <ModuleBase_Operation.h>
#include <Config_FeatureMessage.h>
- #include <Config_WidgetMessage.h>
+ #include <Config_PointerMessage.h>
#include <QApplication>
#include <QFileDialog>
QMdiSubWindow* aWnd = myMainWindow->viewer()->createView();
aWnd->showMaximized();
myMainWindow->showPythonConsole();
- //std::shared_ptr<ModelAPI_Feature> aPoint1 = aMgr->rootDocument()->addFeature("Point");
+
++ // Testing of document creation
+ std::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
- //aMgr->setCurrentDocument(aPart->data()->docRef("PartDocument")->value());
- //std::shared_ptr<ModelAPI_Feature> aPoint2 = aMgr->rootDocument()->addFeature("Point");
++ std::shared_ptr<ModelAPI_Feature> aPoint1 = aMgr->rootDocument()->addFeature("Point");
+ std::shared_ptr<ModelAPI_Feature> aPart = aMgr->rootDocument()->addFeature("Part");
+ aPart->execute();
++ aMgr->setCurrentDocument(aPart->data()->docRef("PartDocument")->value());
++ std::shared_ptr<ModelAPI_Feature> aPoint2 = aMgr->rootDocument()->addFeature("Point");
++ aPoint2 = aMgr->rootDocument()->addFeature("Point");
++
++ aPart = aMgr->rootDocument()->addFeature("Part");
++ aPart->execute();
}
//******************************************************
<file>pictures/part_ico.png</file>
<file>pictures/properties.png</file>
<file>pictures/features.png</file>
++ <file>pictures/point_ico.png</file>
<file>pictures/x_point.png</file>
<file>pictures/y_point.png</file>