{
// TODO: optimize this method
shared_ptr<ModelAPI_Iterator> anIter = featuresIterator(theGroupID);
- for(int a = 0; a != theIndex; anIter->next()) a++;
- return anIter->current();
+ for(int a = 0; a != theIndex && anIter->more(); anIter->next()) a++;
+ return anIter->more() ? anIter->current() : shared_ptr<ModelAPI_Feature>();
}
const vector<string>& Model_Document::getGroups() const
XGUI_ViewBackground.h
XGUI_WidgetFactory.h
XGUI_DocumentDataModel.h
- XGUI_DataModel.h
+ XGUI_PartDataModel.h
XGUI_ObjectsBrowser.h
)
XGUI_ViewBackground.cpp
XGUI_WidgetFactory.cpp
XGUI_DocumentDataModel.cpp
- XGUI_DataModel.cpp
+ XGUI_PartDataModel.cpp
XGUI_ObjectsBrowser.cpp
)
${Qt5Widgets_LIBRARIES}
${CAS_VIEWER}
${CAS_KERNEL}
+ ${CAS_OCAF}
PyConsole
PyInterp
PyEvent
${PROJECT_SOURCE_DIR}/src/PyInterp
${PROJECT_SOURCE_DIR}/src/PyConsole
${PROJECT_SOURCE_DIR}/src/ModelAPI
+ ${PROJECT_SOURCE_DIR}/src/Model
${CAS_INCLUDE_DIRS})
LINK_DIRECTORIES($ENV{PYTHON_LIB_DIR})
+++ /dev/null
-#include "XGUI_DataModel.h"
-
-
-XGUI_DataModel::XGUI_DataModel(QObject* theParent)
- : QAbstractItemModel(theParent)
-{
-}
-
-
-XGUI_DataModel::~XGUI_DataModel()
-{
-}
+++ /dev/null
-
-#ifndef XGUI_DataModel_H
-#define XGUI_DataModel_H
-
-#include <QAbstractItemModel>
-
-class XGUI_DataModel : public QAbstractItemModel
-{
- Q_OBJECT
-public:
- XGUI_DataModel(QObject* theParent);
- virtual ~XGUI_DataModel();
-};
-
-#endif
\ No newline at end of file
#include "XGUI_DocumentDataModel.h"
+#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 <Model_Document.h>
+#include <Event_Loop.h>
+#include <QIcon>
+
XGUI_DocumentDataModel::XGUI_DocumentDataModel(QObject* theParent)
- : QAbstractItemModel(theParent),
- myParamsFolder(0),
- myConstructFolder(0)
+ : QAbstractItemModel(theParent)
{
- //std::shared_ptr<ModelAPI_Feature> myRoot = aMgr->createFeature("Point");
std::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
myDocument = aMgr->currentDocument();
+
+ Event_Loop::loop()->registerListener(this, Event_Loop::eventByName(EVENT_FEATURE_UPDATED));
+
+ myModel = new XGUI_TopDataModel(this);
+ myModel->setDocument(myDocument);
}
}
-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();
+ }
+ while (myPartModels.size() < aNbParts) {
+ myPartModels.append(new XGUI_PartDataModel(this));
}
- break;
- case Qt::DecorationRole:
- // return an Icon
- break;
- case Qt::ToolTipRole:
- // return Tooltip
- break;
+ for (int i = 0; i < myPartModels.size(); i++)
+ myPartModels.at(i)->setDocument(myDocument, i);
}
- return QVariant();
+ endResetModel();
}
+QVariant XGUI_DocumentDataModel::data(const QModelIndex& theIndex, int theRole) const
+{
+ if (!theIndex.isValid())
+ return QVariant();
+ return toSourceModel(theIndex).data(theRole);
+}
-QVariant XGUI_DocumentDataModel::headerData(int section, Qt::Orientation orientation, int role) const
+
+QVariant XGUI_DocumentDataModel::headerData(int theSection, Qt::Orientation theOrient, int theRole) const
{
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);
- int a = aIt->numIterationsLeft();
- return aIt->numIterationsLeft() + 2;
+ if (!theParent.isValid())
+ return myModel->rowCount(theParent) + myPartModels.size();
+
+ return 0;
}
-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());
}
- return QModelIndex();
+ return aIndex;
}
-QModelIndex XGUI_DocumentDataModel::parent(const QModelIndex &index) const
+QModelIndex XGUI_DocumentDataModel::parent(const QModelIndex& theIndex) const
{
return QModelIndex();
}
+
bool XGUI_DocumentDataModel::hasChildren(const QModelIndex& theParent) const
{
if (!theParent.isValid())
return true;
-
- if (theParent.internalId() == quintptr(&myParamsFolder))
- return myDocument->featuresIterator(PARAMETERS_GROUP)->more();
- if (theParent.internalId() == quintptr(&myConstructFolder))
- return myDocument->featuresIterator(CONSTRUCTIONS_GROUP)->more();
return false;
-}
\ No newline at end of file
+}
+
+
+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();
+}
+
+
#define XGUI_DocumentDataModel_H
#include <QAbstractItemModel>
+#include <Event_Listener.h>
+
+#include <QList>
class ModelAPI_Document;
+class XGUI_PartDataModel;
+class XGUI_TopDataModel;
+
-class XGUI_DocumentDataModel : public QAbstractItemModel
+class XGUI_DocumentDataModel : public QAbstractItemModel, public Event_Listener
{
Q_OBJECT
public:
XGUI_DocumentDataModel(QObject* theParent);
virtual ~XGUI_DocumentDataModel();
+ // Event Listener method
+ virtual void processEvent(const Event_Message* theMessage);
+
virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
- virtual QVariant headerData(int section, Qt::Orientation orientation,
- int role = Qt::DisplayRole) const;
+ virtual QVariant headerData(int theSection, Qt::Orientation theOrient,
+ int theRole = Qt::DisplayRole) const;
- virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
- virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
+ virtual int rowCount(const QModelIndex& theParent = QModelIndex()) const;
+ virtual int columnCount(const QModelIndex& theParent = QModelIndex()) const;
virtual QModelIndex index(int theRow, int theColumn,
const QModelIndex &parent = QModelIndex()) const;
- virtual QModelIndex parent(const QModelIndex &index) const;
+ virtual QModelIndex parent(const QModelIndex& theIndex) const;
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;
+
std::shared_ptr<ModelAPI_Document> myDocument;
+
+ XGUI_TopDataModel* myModel;
+ QList<XGUI_PartDataModel*> myPartModels;
};
#endif
\ No newline at end of file
#include "XGUI_ObjectsBrowser.h"
#include "XGUI_DocumentDataModel.h"
+//#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 <Model_Document.h>
XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent)
: QTreeView(theParent)
{
setHeaderHidden(true);
- myDocModel = new XGUI_DocumentDataModel(this);
- setModel(myDocModel);
+ XGUI_DocumentDataModel* aDocModel = new XGUI_DocumentDataModel(this);
+ //std::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
+ //std::shared_ptr<ModelAPI_Document> aDocument = aMgr->currentDocument();
+ //aDocModel->setDocument(aDocument, 0);
+ setModel(aDocModel);
}
XGUI_ObjectsBrowser(QWidget* theParent);
virtual ~XGUI_ObjectsBrowser();
- XGUI_DocumentDataModel* dataModel() const { return myDocModel; }
+ QAbstractItemModel* dataModel() const { return myDocModel; }
private:
- XGUI_DocumentDataModel* myDocModel;
+ QAbstractItemModel* myDocModel;
};
#endif
\ No newline at end of file
--- /dev/null
+#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.model() == this) {
+ if (theIndex.internalId() == ParamsFolder)
+ return tr("Parameters");
+
+ if (theIndex.internalId() == ParamObject) {
+ std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARAMETERS_GROUP, theIndex.row());
+ return aFeature->data()->getName().c_str();
+ }
+ if (theIndex.internalId() == ConstructFolder)
+ return tr("Constructions");
+
+ if (theIndex.internalId() == ConstructObject) {
+ std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(CONSTRUCTIONS_GROUP, theIndex.row());
+ return aFeature->data()->getName().c_str();
+ }
+ }
+ break;
+
+ case Qt::DecorationRole:
+ // return an Icon
+ if (theIndex.model() == this) {
+ if (theIndex.internalId() == ParamsFolder)
+ return QIcon(":pictures/params_folder.png");
+ else if (theIndex.internalId() == ConstructFolder)
+ return QIcon(":pictures/constr_folder.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 (!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;
+}
+
+
+//******************************************************************
+//******************************************************************
+//******************************************************************
+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() == MyRoot) {
+ std::shared_ptr<ModelAPI_Feature> aFeature = myDocument->feature(PARTS_GROUP, myId);
+ return aFeature->data()->getName().c_str();
+ }
+ if (theIndex.internalId() == ParamsFolder)
+ return tr("Parameters");
+ if (theIndex.internalId() == ConstructFolder)
+ return tr("Constructions");
+ break;
+ case Qt::DecorationRole:
+ // return an Icon
+ if (theIndex.internalId() == MyRoot)
+ return QIcon(":pictures/part_ico.png");
+ if (theIndex.internalId() == ParamsFolder)
+ return QIcon(":pictures/params_folder.png");
+ if (theIndex.internalId() == ConstructFolder)
+ return QIcon(":pictures/constr_folder.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 (parent.internalId() == MyRoot)
+ return 2;
+ 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
+{
+ 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;
+}
--- /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:
+ enum DataIds {
+ MyRoot,
+ ParamsFolder,
+ ParamObject,
+ ConstructFolder,
+ ConstructObject
+ };
+
+ std::shared_ptr<ModelAPI_Document> myDocument;
+ int myId;
+};
+
+#endif
\ No newline at end of file
#include <ModelAPI_PluginManager.h>
#include <ModelAPI_Feature.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_AttributeDocRef.h>
#include <Event_Loop.h>
#include <Config_FeatureMessage.h>
myMainWindow->showPythonConsole();
std::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
- std::shared_ptr<ModelAPI_Feature> myRoot = aMgr->createFeature("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");
}
//******************************************************