b6706d939d89f65083ed98bfff6603039fdad1bf
[occt.git] / tools / ShapeView / ShapeView_ItemShape.hxx
1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement. 
15
16 #ifndef ShapeView_ItemShape_H
17 #define ShapeView_ItemShape_H
18
19 #include <inspector/TreeModel_ItemBase.hxx>
20
21 #include <TopTools_IndexedMapOfShape.hxx>
22
23 #include <Standard.hxx>
24 #include <TCollection_AsciiString.hxx>
25 #include <TopAbs_ShapeEnum.hxx>
26 #include <TopoDS_Shape.hxx>
27
28 #include <Standard_WarningsDisable.hxx>
29 #include <QMap>
30 #include <QVariant>
31 #include <Standard_WarningsRestore.hxx>
32
33 class ShapeView_ItemShape;
34 typedef QExplicitlySharedDataPointer<ShapeView_ItemShape> ShapeView_ItemShapePtr;
35
36 //! \class ShapeView_ItemShape
37 //! This item is connected to TopoDS_Shape.
38 //! Parent is either ShapeView_ItemRoot or ShapeView_ItemShape, children are ShapeView_ItemShape or no children
39 class ShapeView_ItemShape : public TreeModel_ItemBase
40 {
41 public:
42
43   //! Creates an item wrapped by a shared pointer
44   //! \param theRow the item row position in the parent item
45   //! \param theColumn the item column position in the parent item
46   //! \return the pointer to the created item
47   static ShapeView_ItemShapePtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
48   { return ShapeView_ItemShapePtr (new ShapeView_ItemShape (theParent, theRow, theColumn)); }
49
50   //! Destructor
51   virtual ~ShapeView_ItemShape() {}
52
53   //! Returns explode type of the item
54   TopAbs_ShapeEnum ExplodeType() const { return myExplodeType; }
55
56   //! Sets explore type
57   //! \param theType type of item explode. If TopAbs_SHAPE, no explode, only iteration by shape
58   void SetExplodeType (const TopAbs_ShapeEnum theType) { myExplodeType  = theType; }
59
60   //! Returns the current shape
61   const TopoDS_Shape& GetItemShape() const { initItem(); return myShape; }
62
63   //! Returns child(extracted) shape for the current shape by the index
64   //! \param theRowId an index of child shape
65   //! \returns shape instance or NULL
66   Standard_EXPORT TopoDS_Shape Shape (const int theRowId) const;
67
68   //! Returns name of BREP file for the shape if exists
69   //! \return string valuie
70   QString GetFileName() const { return myFileName; }
71
72   //! Sets name of BREP file for the shape if exists
73   //! \return string valuie
74   void SetFileName (const QString& theFileName) { myFileName = theFileName; }
75
76   //! Inits the item, fills internal containers
77   Standard_EXPORT virtual void Init() Standard_OVERRIDE;
78
79   //! Resets cached values
80   Standard_EXPORT virtual void Reset() Standard_OVERRIDE;
81
82   //! Returns data value for the role.
83   //! \param theRole a value role
84   //! \return the value
85   Standard_EXPORT virtual QVariant initValue(const int theRole) const;
86
87   //! \return number of children.
88   Standard_EXPORT virtual int initRowCount() const Standard_OVERRIDE;
89
90   //! Returns stream value of the item to fulfill property panel.
91   //! \return stream value or dummy
92   Standard_EXPORT virtual void initStream (Standard_OStream& theOStream) const Standard_OVERRIDE;
93
94 protected:
95
96   //! Initializes the current item. It is empty because Reset() is also empty.
97   virtual void initItem() const Standard_OVERRIDE;
98
99   //! Creates a child item in the given position.
100   //! \param theRow the child row position
101   //! \param theColumn the child column position
102   //! \return the created item
103   virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn) Standard_OVERRIDE;
104
105   //! Returns number of child shapes. Init item if it is not initialized
106   //! \return integer value
107   int getRowCount() const;
108
109   //! Returns current shape, initialized item if it has not been initialized yet
110   //! \return shape value
111   TopoDS_Shape getShape() const;
112
113 private:
114
115   //! Constructor
116   ShapeView_ItemShape (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
117     : TreeModel_ItemBase (theParent, theRow, theColumn), myExplodeType (TopAbs_SHAPE) {}
118
119 private:
120   TopAbs_ShapeEnum myExplodeType; //!< type of explore own shape and get children
121
122   TopoDS_Shape myShape; //!< current shape
123   QString myFileName; //!< BREP file name
124
125   TopTools_IndexedMapOfShape myChildShapes; //!< cached container of child shapes
126 };
127
128 #endif