Salome HOME
Issue #653 - Double and triple click edges -- Fix Debian dynamic_pointer_cast problem...
[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
27   //! Returns Feature object by the given Model index.
28   //! Returns 0 if the given index is not index of a feature
29   /// \param theIndex a model index
30   virtual ObjectPtr object(const QModelIndex& theIndex) const = 0;
31
32   //! Returns QModelIndex which corresponds to the given feature
33   //! If the feature is not found then index is not valid
34   virtual QModelIndex objectIndex(const ObjectPtr& theFeature) const = 0;
35
36   //! Returns parent index of the given feature
37   virtual QModelIndex findParent(const ObjectPtr& theObject) const = 0;
38
39   //! Returns index corresponded to the group
40   //! \param theGroup a group name
41   virtual QModelIndex findGroup(const std::string& theGroup) const = 0;
42
43   //! Set color of items
44   void setItemsColor(const QColor& theColor)
45   {
46     myItemsColor = theColor;
47   }
48
49   //! Returns color of items
50   QColor itemsColor() const
51   {
52     return myItemsColor;
53   }
54
55  protected:
56    /// Color of items
57   QColor myItemsColor;
58 };
59
60 /**\class PartSet_PartModel
61  * \ingroup GUI
62  * \brief Abstaract class of model object which operates with parts data.
63  */
64 class PartSet_PartModel : public PartSet_FeaturesModel
65 {
66  public:
67    /// Constructor
68    /// \param theParent a parent object
69   PartSet_PartModel(QObject* theParent);
70    /// Destructor 
71   ~PartSet_PartModel();
72
73   /// Set part id
74   /// \param theId a new id
75   void setPart(FeaturePtr thePart)
76   {
77     myPart = thePart;
78   }
79
80   /// Returns Id of the part
81   FeaturePtr part() const { return myPart; }
82
83   //! Returns true if the given document is a sub-document of this tree
84   //! \param theDoc a document to check
85   virtual bool hasDocument(const DocumentPtr& theDoc) const = 0;
86
87   /// Returns position of the part in history 
88   int position() const 
89   {
90     DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
91     return aRootDoc->index(myPart);
92   }
93
94  protected:
95   //! Id of the current part object in the document
96   FeaturePtr myPart;
97 };
98
99 #endif