0027398: Integrate Qt Browser Widget to Open CASCADE Technology
[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 <ShapeView_ItemBase.hxx>
20 #include <Standard.hxx>
21 #include <TCollection_AsciiString.hxx>
22 #include <TopoDS_Shape.hxx>
23
24 #include <QMap>
25 #include <QVariant>
26
27 class ShapeView_ItemShape;
28 typedef QExplicitlySharedDataPointer<ShapeView_ItemShape> ShapeView_ItemShapePtr;
29
30 //! \class ShapeView_ItemShape
31 //! This item is connected to TopoDS_Shape.
32 //! Parent is either ShapeView_ItemRoot or ShapeView_ItemShape, children are ShapeView_ItemShape or no children
33 class ShapeView_ItemShape : public ShapeView_ItemBase
34 {
35 public:
36
37   //! Creates an item wrapped by a shared pointer
38   //! \param theRow the item row positition in the parent item
39   //! \param theColumn the item column positition in the parent item
40   //! \return the pointer to the created item
41   static ShapeView_ItemShapePtr CreateItem (TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
42   { return ShapeView_ItemShapePtr (new ShapeView_ItemShape (theParent, theRow, theColumn)); }
43
44   //! Destructor
45   virtual ~ShapeView_ItemShape() Standard_OVERRIDE {};
46
47   //! Returns the current shape
48   const TopoDS_Shape& GetItemShape() const { return myShape; }
49
50   //! Returns child(extracted) shape for the current shape by the index
51   //! \param theRowId an index of child shape
52   //! \returns shape instance or NULL
53   Standard_EXPORT TopoDS_Shape GetShape (const int theRowId) const;
54
55   //! Returns name of BREP file for the shape if exists
56   //! \return string valuie
57   QString GetFileName() const { return myFileName; }
58
59   //! Sets name of BREP file for the shape if exists
60   //! \return string valuie
61   void SetFileName (const QString& theFileName) { myFileName = theFileName; }
62
63   //! Returns TShape pointer info of the current TopoDS Shape
64   //! \return string value
65   TCollection_AsciiString TShapePointer() const { return getPointerInfo (myShape.TShape()); }
66
67   //! Inits the item, fills internal containers
68   Standard_EXPORT virtual void Init() Standard_OVERRIDE;
69
70   //! Resets cached values
71   Standard_EXPORT virtual void Reset() Standard_OVERRIDE;
72
73   //! Return data value for the role.
74   //! \param theRole a value role
75   //! \return the value
76   Standard_EXPORT virtual QVariant initValue(const int theRole) const;
77
78   //! \return number of children.
79   Standard_EXPORT virtual int initRowCount() const Standard_OVERRIDE;
80
81 protected:
82
83   //! Initialize the current item. It is empty because Reset() is also empty.
84   virtual void initItem() const Standard_OVERRIDE;
85
86   //! Creates a child item in the given position.
87   //! \param theRow the child row position
88   //! \param theColumn the child column position
89   //! \return the created item
90   virtual TreeModel_ItemBasePtr createChild (int theRow, int theColumn) Standard_OVERRIDE;
91
92   //! Returns number of child shapes. Init item if it is not initialized
93   //! \return integer value
94   int getRowCount() const;
95
96   //! Returns current shape, initialized item if it has not been initialized yet
97   //! \return shape value
98   TopoDS_Shape getShape() const;
99
100   //! Convert pointer to string value
101   //! \param thePointer a pointer
102   //! \param isShortInfo if true, all '0' symbols in the beginning of the pointer are skipped
103   //! \return the string value
104   static TCollection_AsciiString getPointerInfo (const Handle(Standard_Transient)& thePointer, const bool isShortInfo = true);
105
106 private:
107
108   //! Constructor
109   ShapeView_ItemShape(TreeModel_ItemBasePtr theParent, const int theRow, const int theColumn)
110   : ShapeView_ItemBase(theParent, theRow, theColumn) {}
111
112 private:
113
114   TopoDS_Shape myShape; //!< current shape
115   QString myFileName; //!< BREP file name
116 };
117
118 #endif