}
//=================================================================================================
-int FeaturesPlugin_CompositeBoolean::numberOfSubs() const
+int FeaturesPlugin_CompositeBoolean::numberOfSubs(bool forTree) const
{
ObjectPtr aObj = data()->reference(SKETCH_OBJECT_ID())->value();
return aObj.get()? 1 : 0;
}
//=================================================================================================
-std::shared_ptr<ModelAPI_Feature> FeaturesPlugin_CompositeBoolean::subFeature(const int theIndex) const
+std::shared_ptr<ModelAPI_Feature> FeaturesPlugin_CompositeBoolean::subFeature(const int theIndex, bool forTree) const
{
if (theIndex == 0)
return std::dynamic_pointer_cast<ModelAPI_Feature>(data()->reference(SKETCH_OBJECT_ID())->value());
FEATURESPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID);
/// \return the number of sub-elements.
- FEATURESPLUGIN_EXPORT virtual int numberOfSubs() const;
+ FEATURESPLUGIN_EXPORT virtual int numberOfSubs(bool forTree = false) const;
/// \return the sub-feature by zero-base index.
- FEATURESPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Feature> subFeature(const int theIndex) const;
+ FEATURESPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Feature> subFeature(const int theIndex, bool forTree = false) const;
/// \return the sub-feature unique identifier in this composite feature by zero-base index.
FEATURESPLUGIN_EXPORT virtual int subFeatureId(const int theIndex) const;
virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID) = 0;
/// Returns the number of sub-elements
- virtual int numberOfSubs() const = 0;
+ virtual int numberOfSubs(bool forTree = false) const = 0;
/// Returns the sub-feature by zero-base index
- virtual std::shared_ptr<ModelAPI_Feature> subFeature(const int theIndex) const = 0;
+ virtual std::shared_ptr<ModelAPI_Feature> subFeature(const int theIndex, bool forTree = false) const = 0;
/// Returns the sub-feature unique identifier in this composite feature by zero-base index
virtual int subFeatureId(const int theIndex) const = 0;
return ResultPtr();
}
+CompositeFeaturePtr compositeOwner(const FeaturePtr& theFeature)
+{
+ if (theFeature.get() && theFeature->data()->isValid()) {
+ const std::set<std::shared_ptr<ModelAPI_Attribute> > aRefs = theFeature->data()->refsToMe();
+ std::set<std::shared_ptr<ModelAPI_Attribute> >::const_iterator aRefIter = aRefs.begin();
+ for(; aRefIter != aRefs.end(); aRefIter++) {
+ CompositeFeaturePtr aComp = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>
+ ((*aRefIter)->owner());
+ if (aComp.get() && aComp->isSub(theFeature))
+ return aComp;
+ }
+ }
+ return CompositeFeaturePtr(); // not found
+}
+
} // namespace ModelAPI_Tools
#include <ModelAPI_Document.h>
#include <ModelAPI_Feature.h>
#include <GeomAPI_Shape.h>
+#include <ModelAPI_CompositeFeature.h>
#include <vector>
*/
MODELAPI_EXPORT ResultPtr findPartResult(const DocumentPtr& theMain, const DocumentPtr& theSub);
+/*!
+ * Returns the cpomposite feature - parent of this feature.
+ * \param theFeature the sub-element of composite
+ * \returns null if it is not sub-element of composite
+ */
+MODELAPI_EXPORT CompositeFeaturePtr compositeOwner(const FeaturePtr& theFeature);
+
}
#endif
PartSet_PartDataModel.h
PartSet_DataTreeModel.h
PartSet_WidgetSketchCreator.h
+ PartSet_TopDataModel.h
)
SET(PROJECT_SOURCES
PartSet_DocumentDataModel.cpp
PartSet_PartDataModel.cpp
PartSet_WidgetSketchCreator.cpp
+ PartSet_TopDataModel.cpp
)
SET(PROJECT_RESOURCES
#include "PartSet_DocumentDataModel.h"
#include "PartSet_PartDataModel.h"
+#include "PartSet_TopDataModel.h"
#include "PartSet_Module.h"
//#include "XGUI_Tools.h"
#include <ModelAPI_ResultGroup.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Events.h>
+#include <ModelAPI_Tools.h>
#include <Events_Loop.h>
#include <QBrush>
-PartSet_TopDataModel::PartSet_TopDataModel(QObject* theParent)
- : PartSet_FeaturesModel(theParent)
-{
-}
-
-PartSet_TopDataModel::~PartSet_TopDataModel()
-{
-}
-
-QVariant PartSet_TopDataModel::data(const QModelIndex& theIndex, int theRole) const
-{
- if (theIndex.column() == 1)
- return QVariant();
-
- switch (theRole) {
- case Qt::DisplayRole:
- // return a name
- switch (theIndex.internalId()) {
- case ParamsFolder:
- return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex));
- case ParamObject: {
- DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
- ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultParameter::group(), theIndex.row());
- if (aObject) {
- ResultParameterPtr aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aObject);
- AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE());
- QString aVal = QString::number(aValueAttribute->value());
- QString aTitle = QString(aObject->data()->name().c_str());
- return aTitle + " = " + aVal;
- }
- }
- break;
- case ConstructFolder:
- return tr("Constructions") + QString(" (%1)").arg(rowCount(theIndex));
- case ConstructObject: {
- DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
- ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultConstruction::group(),
- theIndex.row());
- if (aObject)
- return aObject->data()->name().c_str();
- }
- break;
- //case GroupsFolder:
- // return tr("Groups") + QString(" (%1)").arg(rowCount(theIndex));
- //case GroupObject: {
- // DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
- // ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultGroup::group(),
- // theIndex.row());
- // if (aObject)
- // return aObject->data()->name().c_str();
- //}
- // break;
- }
- break;
-
- case Qt::DecorationRole:
- {
- // return an Icon
- switch (theIndex.internalId()) {
- case ParamsFolder:
- return QIcon(":pictures/params_folder.png");
- case ConstructFolder:
- return QIcon(":pictures/constr_folder.png");
- case ConstructObject:
- return QIcon(":pictures/constr_object.png");
- //case GroupsFolder:
- // return QIcon(":pictures/constr_folder.png");
- }
- }
- break;
-
- case Qt::ToolTipRole:
- // return Tooltip
- break;
- case Qt::ForegroundRole:
- return QBrush(myItemsColor);
- break;
- }
- return QVariant();
-}
-
-QVariant PartSet_TopDataModel::headerData(int section, Qt::Orientation orientation, int role) const
-{
- return QVariant();
-}
-
-int PartSet_TopDataModel::rowCount(const QModelIndex& theParent) const
-{
- if (!theParent.isValid())
- return 2; // In case of groups using it has to be +1
-
- DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
- if (theParent.internalId() == ParamsFolder)
- return aRootDoc->size(ModelAPI_ResultParameter::group());
-
- if (theParent.internalId() == ConstructFolder)
- return aRootDoc->size(ModelAPI_ResultConstruction::group());
-
- //if (theParent.internalId() == GroupsFolder)
- // return aRootDoc->size(ModelAPI_ResultGroup::group());
-
- return 0;
-}
-
-int PartSet_TopDataModel::columnCount(const QModelIndex &parent) const
-{
- return 1;
-}
-
-QModelIndex PartSet_TopDataModel::index(int theRow, int theColumn, const QModelIndex& theParent) const
-{
- if (!theParent.isValid()) {
- switch (theRow) {
- case 0:
- return createIndex(theRow, theColumn, (qint32) ParamsFolder);
- case 1:
- return createIndex(theRow, theColumn, (qint32) ConstructFolder);
- //case 2:
- // return createIndex(theRow, theColumn, (qint32) GroupsFolder);
- }
- } else {
- if (theParent.internalId() == ParamsFolder)
- return createIndex(theRow, theColumn, (qint32) ParamObject);
-
- if (theParent.internalId() == ConstructFolder)
- return createIndex(theRow, theColumn, (qint32) ConstructObject);
-
- //if (theParent.internalId() == GroupsFolder)
- // return createIndex(theRow, theColumn, (qint32) GroupObject);
- }
- return QModelIndex();
-}
-
-QModelIndex PartSet_TopDataModel::parent(const QModelIndex& theIndex) const
-{
- int aId = (int) theIndex.internalId();
- switch (aId) {
- case ParamsFolder:
- case ConstructFolder:
- //case GroupsFolder:
- return QModelIndex();
- case ParamObject:
- return createIndex(0, 0, (qint32) ParamsFolder);
- case ConstructObject:
- return createIndex(1, 0, (qint32) ConstructFolder);
- //case GroupObject:
- // return createIndex(2, 0, (qint32) GroupsFolder);
- }
- return QModelIndex();
-}
-
-bool PartSet_TopDataModel::hasChildren(const QModelIndex& theParent) const
-{
- return rowCount(theParent) > 0;
-}
-
-ObjectPtr PartSet_TopDataModel::object(const QModelIndex& theIndex) const
-{
- switch (theIndex.internalId()) {
- case ParamsFolder:
- case ConstructFolder:
- return ObjectPtr();
- case ParamObject: {
- DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
- return aRootDoc->object(ModelAPI_ResultParameter::group(), theIndex.row());
- }
- case ConstructObject: {
- DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
- return aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row());
- }
- //case GroupObject: {
- // DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
- // return aRootDoc->object(ModelAPI_ResultGroup::group(), theIndex.row());
- //}
- }
- return ObjectPtr();
-}
-
-QModelIndex PartSet_TopDataModel::findParent(const ObjectPtr& theObject) const
-{
- return findGroup(theObject->groupName().c_str());
-}
-
-QModelIndex PartSet_TopDataModel::findGroup(const std::string& theGroup) const
-{
- if (theGroup == ModelAPI_ResultParameter::group())
- return createIndex(0, 0, (qint32) ParamsFolder);
- if (theGroup == ModelAPI_ResultConstruction::group())
- return createIndex(1, 0, (qint32) ConstructFolder);
- //if (theGroup == ModelAPI_ResultGroup::group())
- // return createIndex(2, 0, (qint32) ConstructFolder);
- return QModelIndex();
-}
-
-QModelIndex PartSet_TopDataModel::objectIndex(const ObjectPtr& theObject) const
-{
- QModelIndex aIndex;
- if (theObject) {
- DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
- std::string aGroup = theObject->groupName();
- int aNb = aRootDoc->size(aGroup);
- int aRow = -1;
- for (int i = 0; i < aNb; i++) {
- if (aRootDoc->object(aGroup, i) == theObject) {
- aRow = i;
- break;
- }
- }
- if (aRow != -1) {
- if (aGroup == ModelAPI_ResultParameter::group())
- return createIndex(aRow, 0, (qint32) ParamObject);
- if (aGroup == ModelAPI_ResultConstruction::group())
- return createIndex(aRow, 0, (qint32) ConstructObject);
- //if (aGroup == ModelAPI_ResultGroup::group())
- // return createIndex(aRow, 0, (qint32) GroupObject);
- }
- }
- return aIndex;
-}
-
-//******************************************************************
-//******************************************************************
-//******************************************************************
PartSet_PartDataModel::PartSet_PartDataModel(QObject* theParent)
: PartSet_PartModel(theParent)
{
return QVariant();
}
+ if (theIndex.internalId() >= 0) {
+ ObjectPtr aObj = object(theIndex);
+ switch (theRole) {
+ case Qt::DisplayRole:
+ return aObj->data()->name().c_str();
+ case Qt::DecorationRole:
+ {
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aObj);
+ if (aFeature)
+ return PartSet_DocumentDataModel::featureIcon(aFeature);
+ }
+ break;
+ case Qt::ForegroundRole:
+ if (theIndex.internalId() > lastHistoryRow())
+ return QBrush(Qt::lightGray);
+ return QBrush(myItemsColor);
+ }
+ }
+
switch (theRole) {
case Qt::DisplayRole:
// return a name
return partDocument()->size(ModelAPI_ResultBody::group());
case GroupsFolder:
return partDocument()->size(ModelAPI_ResultGroup::group());
+ case HistoryObject:
+ {
+ ObjectPtr aObj = object(parent);
+ CompositeFeaturePtr aCompFeature =
+ std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aObj);
+ if (aCompFeature.get()) {
+ return aCompFeature->numberOfSubs(true);
+ }
+ }
}
return 0;
}
return createIndex(theRow, theColumn, (qint32) BodiesObject);
case GroupsFolder:
return createIndex(theRow, theColumn, (qint32) GroupObject);
+ case HistoryObject:
+ {
+ return createIndex(theRow, theColumn, (qint32) theParent.row());
+ }
}
}
return QModelIndex();
QModelIndex PartSet_PartDataModel::parent(const QModelIndex& theIndex) const
{
+ if (theIndex.internalId() >= 0) {
+ int aPRow = theIndex.internalId();
+ return createIndex(aPRow, 0, (qint32) HistoryObject);
+ }
switch (theIndex.internalId()) {
case ParamsFolder:
case ConstructFolder:
ObjectPtr PartSet_PartDataModel::object(const QModelIndex& theIndex) const
{
+ if (theIndex.internalId() >= 0) {
+ int aPRow = theIndex.internalId();
+ ObjectPtr aObj =
+ partDocument()->object(ModelAPI_Feature::group(), aPRow - getRowsNumber());
+ CompositeFeaturePtr aCompFeature =
+ std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aObj);
+ if (aCompFeature.get()) {
+ return aCompFeature->subFeature(theIndex.row(), true);
+ }
+ return ObjectPtr();
+ }
switch (theIndex.internalId()) {
case ParamsFolder:
case ConstructFolder:
#include "PartSet.h"
#include "PartSet_DataTreeModel.h"
-/**\class PartSet_TopDataModel
- * \ingroup GUI
- * \brief This is a data model for Object Browser (QTreeView).
- * It represents only upper part of data tree (non-parts tree items)
- */
-class PARTSET_EXPORT PartSet_TopDataModel : public PartSet_FeaturesModel
-{
-Q_OBJECT
- public:
- /// Constructor
- /// \param theParent a parent object
- PartSet_TopDataModel(QObject* theParent);
- virtual ~PartSet_TopDataModel();
-
- // Reimpl from QAbstractItemModel
-
- /// Returns the data stored under the given role for the item referred to by the index.
- /// \param theIndex a model index
- /// \param theRole a data role (see Qt::ItemDataRole)
- virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
-
- /// Returns the data for the given role and section in the header with the specified orientation.
- /// \param theSection a section
- /// \param theOrient an orientation
- /// \param theRole a data role (see Qt::ItemDataRole)
- virtual QVariant headerData(int theSection, Qt::Orientation theOrient,
- int theRole = Qt::DisplayRole) const;
-
- /// Returns the number of rows under the given parent. When the parent is valid it means that
- /// rowCount is returning the number of children of parent.
- /// \param theParent a parent model index
- virtual int rowCount(const QModelIndex &theParent = QModelIndex()) const;
-
- /// Returns the number of columns for the children of the given parent.
- /// It has a one column
- /// \param theParent a parent model index
- virtual int columnCount(const QModelIndex &theParent = QModelIndex()) const;
-
-
- /// Returns the index of the item in the model specified by the given row, column and parent index.
- /// \param theRow a row
- /// \param theColumn a column
- /// \param theParent a parent model index
- virtual QModelIndex index(int theRow, int theColumn, const QModelIndex& theParent =
- QModelIndex()) const;
-
- /// Returns the parent of the model item with the given index.
- /// If the item has no parent, an invalid QModelIndex is returned.
- /// \param theIndex a model index
- virtual QModelIndex parent(const QModelIndex& theIndex) const;
-
- /// Returns true if parent has any children; otherwise returns false.
- /// \param theParent a parent model index
- virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
-
- //! Returns object by the given Model index.
- //! Returns 0 if the given index is not index of a object
- virtual ObjectPtr object(const QModelIndex& theIndex) const;
-
- //! Returns QModelIndex which corresponds to the given object
- //! If the object is not found then index is not valid
- virtual QModelIndex objectIndex(const ObjectPtr& theObject) const;
-
- //! Returns parent index of the given object
- virtual QModelIndex findParent(const ObjectPtr& theObject) const;
-
- //! Returns index corresponded to the group
- virtual QModelIndex findGroup(const std::string& theGroup) const;
-
- private:
- //! Types of QModelIndexes
- enum DataIds
- {
- ParamsFolder,
- ParamObject,
- ConstructFolder,
- ConstructObject
- //GroupsFolder,
- //GroupObject
- };
-
-};
/**\class PartSet_PartDataModel
* \ingroup GUI
int lastHistoryRow() const;
//! Types of QModelIndexes
+ //! All types have negative Id's. Positive Id means sub-feature and contains row of its parent
enum DataIds
{
//MyRoot,
- ParamsFolder,
+ ParamsFolder = -100,
ParamObject,
ConstructFolder,
ConstructObject,
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+#include "PartSet_TopDataModel.h"
+#include "PartSet_Module.h"
+#include "PartSet_DocumentDataModel.h"
+
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_Feature.h>
+#include <ModelAPI_Result.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_AttributeDocRef.h>
+#include <ModelAPI_Object.h>
+#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_ResultParameter.h>
+#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultGroup.h>
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_Events.h>
+
+#include <Events_Loop.h>
+
+#include <QIcon>
+#include <QBrush>
+
+
+PartSet_TopDataModel::PartSet_TopDataModel(QObject* theParent)
+ : PartSet_FeaturesModel(theParent)
+{
+}
+
+PartSet_TopDataModel::~PartSet_TopDataModel()
+{
+}
+
+QVariant PartSet_TopDataModel::data(const QModelIndex& theIndex, int theRole) const
+{
+ if (theIndex.column() == 1)
+ return QVariant();
+
+ switch (theRole) {
+ case Qt::DisplayRole:
+ // return a name
+ switch (theIndex.internalId()) {
+ case ParamsFolder:
+ return tr("Parameters") + QString(" (%1)").arg(rowCount(theIndex));
+ case ParamObject: {
+ DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+ ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultParameter::group(), theIndex.row());
+ if (aObject) {
+ ResultParameterPtr aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aObject);
+ AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE());
+ QString aVal = QString::number(aValueAttribute->value());
+ QString aTitle = QString(aObject->data()->name().c_str());
+ return aTitle + " = " + aVal;
+ }
+ }
+ break;
+ case ConstructFolder:
+ return tr("Constructions") + QString(" (%1)").arg(rowCount(theIndex));
+ case ConstructObject: {
+ DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+ ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultConstruction::group(),
+ theIndex.row());
+ if (aObject)
+ return aObject->data()->name().c_str();
+ }
+ break;
+ //case GroupsFolder:
+ // return tr("Groups") + QString(" (%1)").arg(rowCount(theIndex));
+ //case GroupObject: {
+ // DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+ // ObjectPtr aObject = aRootDoc->object(ModelAPI_ResultGroup::group(),
+ // theIndex.row());
+ // if (aObject)
+ // return aObject->data()->name().c_str();
+ //}
+ // break;
+ }
+ break;
+
+ case Qt::DecorationRole:
+ {
+ // return an Icon
+ switch (theIndex.internalId()) {
+ case ParamsFolder:
+ return QIcon(":pictures/params_folder.png");
+ case ConstructFolder:
+ return QIcon(":pictures/constr_folder.png");
+ case ConstructObject:
+ return QIcon(":pictures/constr_object.png");
+ //case GroupsFolder:
+ // return QIcon(":pictures/constr_folder.png");
+ }
+ }
+ break;
+
+ case Qt::ToolTipRole:
+ // return Tooltip
+ break;
+ case Qt::ForegroundRole:
+ return QBrush(myItemsColor);
+ break;
+ }
+ return QVariant();
+}
+
+QVariant PartSet_TopDataModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ return QVariant();
+}
+
+int PartSet_TopDataModel::rowCount(const QModelIndex& theParent) const
+{
+ if (!theParent.isValid())
+ return 2; // In case of groups using it has to be +1
+
+ DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+ if (theParent.internalId() == ParamsFolder)
+ return aRootDoc->size(ModelAPI_ResultParameter::group());
+
+ if (theParent.internalId() == ConstructFolder)
+ return aRootDoc->size(ModelAPI_ResultConstruction::group());
+
+ //if (theParent.internalId() == GroupsFolder)
+ // return aRootDoc->size(ModelAPI_ResultGroup::group());
+
+ return 0;
+}
+
+int PartSet_TopDataModel::columnCount(const QModelIndex &parent) const
+{
+ return 1;
+}
+
+QModelIndex PartSet_TopDataModel::index(int theRow, int theColumn, const QModelIndex& theParent) const
+{
+ if (!theParent.isValid()) {
+ switch (theRow) {
+ case 0:
+ return createIndex(theRow, theColumn, (qint32) ParamsFolder);
+ case 1:
+ return createIndex(theRow, theColumn, (qint32) ConstructFolder);
+ //case 2:
+ // return createIndex(theRow, theColumn, (qint32) GroupsFolder);
+ }
+ } else {
+ if (theParent.internalId() == ParamsFolder)
+ return createIndex(theRow, theColumn, (qint32) ParamObject);
+
+ if (theParent.internalId() == ConstructFolder)
+ return createIndex(theRow, theColumn, (qint32) ConstructObject);
+
+ //if (theParent.internalId() == GroupsFolder)
+ // return createIndex(theRow, theColumn, (qint32) GroupObject);
+ }
+ return QModelIndex();
+}
+
+QModelIndex PartSet_TopDataModel::parent(const QModelIndex& theIndex) const
+{
+ int aId = (int) theIndex.internalId();
+ switch (aId) {
+ case ParamsFolder:
+ case ConstructFolder:
+ //case GroupsFolder:
+ return QModelIndex();
+ case ParamObject:
+ return createIndex(0, 0, (qint32) ParamsFolder);
+ case ConstructObject:
+ return createIndex(1, 0, (qint32) ConstructFolder);
+ //case GroupObject:
+ // return createIndex(2, 0, (qint32) GroupsFolder);
+ }
+ return QModelIndex();
+}
+
+bool PartSet_TopDataModel::hasChildren(const QModelIndex& theParent) const
+{
+ return rowCount(theParent) > 0;
+}
+
+ObjectPtr PartSet_TopDataModel::object(const QModelIndex& theIndex) const
+{
+ switch (theIndex.internalId()) {
+ case ParamsFolder:
+ case ConstructFolder:
+ return ObjectPtr();
+ case ParamObject: {
+ DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+ return aRootDoc->object(ModelAPI_ResultParameter::group(), theIndex.row());
+ }
+ case ConstructObject: {
+ DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+ return aRootDoc->object(ModelAPI_ResultConstruction::group(), theIndex.row());
+ }
+ //case GroupObject: {
+ // DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+ // return aRootDoc->object(ModelAPI_ResultGroup::group(), theIndex.row());
+ //}
+ }
+ return ObjectPtr();
+}
+
+QModelIndex PartSet_TopDataModel::findParent(const ObjectPtr& theObject) const
+{
+ return findGroup(theObject->groupName().c_str());
+}
+
+QModelIndex PartSet_TopDataModel::findGroup(const std::string& theGroup) const
+{
+ if (theGroup == ModelAPI_ResultParameter::group())
+ return createIndex(0, 0, (qint32) ParamsFolder);
+ if (theGroup == ModelAPI_ResultConstruction::group())
+ return createIndex(1, 0, (qint32) ConstructFolder);
+ //if (theGroup == ModelAPI_ResultGroup::group())
+ // return createIndex(2, 0, (qint32) ConstructFolder);
+ return QModelIndex();
+}
+
+QModelIndex PartSet_TopDataModel::objectIndex(const ObjectPtr& theObject) const
+{
+ QModelIndex aIndex;
+ if (theObject) {
+ DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
+ std::string aGroup = theObject->groupName();
+ int aNb = aRootDoc->size(aGroup);
+ int aRow = -1;
+ for (int i = 0; i < aNb; i++) {
+ if (aRootDoc->object(aGroup, i) == theObject) {
+ aRow = i;
+ break;
+ }
+ }
+ if (aRow != -1) {
+ if (aGroup == ModelAPI_ResultParameter::group())
+ return createIndex(aRow, 0, (qint32) ParamObject);
+ if (aGroup == ModelAPI_ResultConstruction::group())
+ return createIndex(aRow, 0, (qint32) ConstructObject);
+ //if (aGroup == ModelAPI_ResultGroup::group())
+ // return createIndex(aRow, 0, (qint32) GroupObject);
+ }
+ }
+ return aIndex;
+}
+
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+#ifndef PartSet_TopDataModel_H
+#define PartSet_TopDataModel_H
+
+#include "PartSet.h"
+#include "PartSet_DataTreeModel.h"
+
+/**\class PartSet_TopDataModel
+ * \ingroup GUI
+ * \brief This is a data model for Object Browser (QTreeView).
+ * It represents only upper part of data tree (non-parts tree items)
+ */
+class PARTSET_EXPORT PartSet_TopDataModel : public PartSet_FeaturesModel
+{
+Q_OBJECT
+ public:
+ /// Constructor
+ /// \param theParent a parent object
+ PartSet_TopDataModel(QObject* theParent);
+ virtual ~PartSet_TopDataModel();
+
+ // Reimpl from QAbstractItemModel
+
+ /// Returns the data stored under the given role for the item referred to by the index.
+ /// \param theIndex a model index
+ /// \param theRole a data role (see Qt::ItemDataRole)
+ virtual QVariant data(const QModelIndex& theIndex, int theRole) const;
+
+ /// Returns the data for the given role and section in the header with the specified orientation.
+ /// \param theSection a section
+ /// \param theOrient an orientation
+ /// \param theRole a data role (see Qt::ItemDataRole)
+ virtual QVariant headerData(int theSection, Qt::Orientation theOrient,
+ int theRole = Qt::DisplayRole) const;
+
+ /// Returns the number of rows under the given parent. When the parent is valid it means that
+ /// rowCount is returning the number of children of parent.
+ /// \param theParent a parent model index
+ virtual int rowCount(const QModelIndex &theParent = QModelIndex()) const;
+
+ /// Returns the number of columns for the children of the given parent.
+ /// It has a one column
+ /// \param theParent a parent model index
+ virtual int columnCount(const QModelIndex &theParent = QModelIndex()) const;
+
+
+ /// Returns the index of the item in the model specified by the given row, column and parent index.
+ /// \param theRow a row
+ /// \param theColumn a column
+ /// \param theParent a parent model index
+ virtual QModelIndex index(int theRow, int theColumn, const QModelIndex& theParent =
+ QModelIndex()) const;
+
+ /// Returns the parent of the model item with the given index.
+ /// If the item has no parent, an invalid QModelIndex is returned.
+ /// \param theIndex a model index
+ virtual QModelIndex parent(const QModelIndex& theIndex) const;
+
+ /// Returns true if parent has any children; otherwise returns false.
+ /// \param theParent a parent model index
+ virtual bool hasChildren(const QModelIndex& theParent = QModelIndex()) const;
+
+ //! Returns object by the given Model index.
+ //! Returns 0 if the given index is not index of a object
+ virtual ObjectPtr object(const QModelIndex& theIndex) const;
+
+ //! Returns QModelIndex which corresponds to the given object
+ //! If the object is not found then index is not valid
+ virtual QModelIndex objectIndex(const ObjectPtr& theObject) const;
+
+ //! Returns parent index of the given object
+ virtual QModelIndex findParent(const ObjectPtr& theObject) const;
+
+ //! Returns index corresponded to the group
+ virtual QModelIndex findGroup(const std::string& theGroup) const;
+
+ private:
+ //! Types of QModelIndexes
+ enum DataIds
+ {
+ ParamsFolder,
+ ParamObject,
+ ConstructFolder,
+ ConstructObject
+ //GroupsFolder,
+ //GroupObject
+ };
+
+};
+
+#endif
\ No newline at end of file
return FeaturePtr();
}
-int PartSetPlugin_Part::numberOfSubs() const
+int PartSetPlugin_Part::numberOfSubs(bool forTree) const
{
ResultPartPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultPart>(firstResult());
if (aResult.get()) {
return 0;
}
-std::shared_ptr<ModelAPI_Feature> PartSetPlugin_Part::subFeature(const int theIndex) const
+std::shared_ptr<ModelAPI_Feature> PartSetPlugin_Part::subFeature(const int theIndex, bool forTree) const
{
ResultPartPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultPart>(firstResult());
if (aResult.get()) {
virtual std::shared_ptr<ModelAPI_Feature> addFeature(std::string theID);
/// Returns the number of sub-features of the document
- virtual int numberOfSubs() const;
+ virtual int numberOfSubs(bool forTree = false) const;
/// Returns the sub-feature by zero-base index
- virtual std::shared_ptr<ModelAPI_Feature> subFeature(const int theIndex) const;
+ virtual std::shared_ptr<ModelAPI_Feature> subFeature(const int theIndex, bool forTree = false) const;
/// Returns the sub-feature unique identifier in this composite feature by zero-base index
virtual int subFeatureId(const int theIndex) const;
data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->remove(ObjectPtr());
}
-int SketchPlugin_Sketch::numberOfSubs() const
+int SketchPlugin_Sketch::numberOfSubs(bool forTree) const
{
return data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->size();
}
-std::shared_ptr<ModelAPI_Feature> SketchPlugin_Sketch::subFeature(const int theIndex) const
+std::shared_ptr<ModelAPI_Feature> SketchPlugin_Sketch::subFeature(const int theIndex, bool forTree) const
{
ObjectPtr anObj = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->object(theIndex);
return std::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
virtual void removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature);
/// Returns the number of sub-elements
- SKETCHPLUGIN_EXPORT virtual int numberOfSubs() const;
+ SKETCHPLUGIN_EXPORT virtual int numberOfSubs(bool forTree = false) const;
/// Returns the sub-feature by zero-base index
SKETCHPLUGIN_EXPORT virtual std::shared_ptr<ModelAPI_Feature>
- subFeature(const int theIndex) const;
+ subFeature(const int theIndex, bool forTree = false) const;
/// Returns the sub-feature unique identifier in this composite feature by zero-base index
SKETCHPLUGIN_EXPORT virtual int subFeatureId(const int theIndex) const;