Salome HOME
Abort operation ExtrusionCur if sketcher was aborted
[modules/shaper.git] / src / PartSet / PartSet_DataTreeModel.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 #ifndef PartSet_DataTreeModel_H
4 #define PartSet_DataTreeModel_H
5
6 #include "PartSet.h"
7
8 #include <ModelAPI_Document.h>
9 #include <ModelAPI_Feature.h>
10 #include <ModelAPI_ResultPart.h>
11 #include <ModelAPI_Session.h>
12
13 #include <QAbstractItemModel>
14 #include <QColor>
15
16 /**\class PartSet_FeaturesModel
17  * \ingroup GUI
18  * \brief Abstaract class of model object which operates with features data.
19  */
20 class PARTSET_EXPORT PartSet_FeaturesModel : public QAbstractItemModel
21 {
22  public:
23    /// Constructor
24    /// \param theParent a parent object
25   PartSet_FeaturesModel(QObject* theParent)
26       : QAbstractItemModel(theParent),
27         myItemsColor(Qt::black)
28   {
29   }
30
31   //! Returns Feature object by the given Model index.
32   //! Returns 0 if the given index is not index of a feature
33   /// \param theIndex a model index
34   virtual ObjectPtr object(const QModelIndex& theIndex) const = 0;
35
36   //! Returns QModelIndex which corresponds to the given feature
37   //! If the feature is not found then index is not valid
38   virtual QModelIndex objectIndex(const ObjectPtr& theFeature) const = 0;
39
40   //! Returns parent index of the given feature
41   virtual QModelIndex findParent(const ObjectPtr& theObject) const = 0;
42
43   //! Returns index corresponded to the group
44   //! \param theGroup a group name
45   virtual QModelIndex findGroup(const std::string& theGroup) const = 0;
46
47   //! Set color of items
48   void setItemsColor(const QColor& theColor)
49   {
50     myItemsColor = theColor;
51   }
52
53   //! Returns color of items
54   QColor itemsColor() const
55   {
56     return myItemsColor;
57   }
58
59  protected:
60    /// Color of items
61   QColor myItemsColor;
62 };
63
64 /**\class PartSet_PartModel
65  * \ingroup GUI
66  * \brief Abstaract class of model object which operates with parts data.
67  */
68 class PartSet_PartModel : public PartSet_FeaturesModel
69 {
70  public:
71    /// Constructor
72    /// \param theParent a parent object
73   PartSet_PartModel(QObject* theParent)
74       : PartSet_FeaturesModel(theParent)
75   {
76   }
77   ~PartSet_PartModel()
78   {
79     myPart = FeaturePtr();
80   }
81
82   /// Set part id
83   /// \param theId a new id
84   void setPart(FeaturePtr thePart)
85   {
86     myPart = thePart;
87   }
88
89   /// Returns Id of the part
90   FeaturePtr part() const { return myPart; }
91
92   //! Returns true if the given document is a sub-document of this tree
93   //! \param theDoc a document to check
94   virtual bool hasDocument(const DocumentPtr& theDoc) const = 0;
95
96   /// Returns position of the part in history 
97   int position() const 
98   {
99     DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
100     return aRootDoc->index(myPart);
101   }
102
103  protected:
104   //! Id of the current part object in the document
105   FeaturePtr myPart;
106 };
107
108 #endif