]> SALOME platform Git repositories - modules/hexablock.git/blob - src/HEXABLOCKGUI/MyGEOMBase_Helper.hxx
Salome HOME
4bfdab26a494a56bb0a46539aeaa30e46c7169b9
[modules/hexablock.git] / src / HEXABLOCKGUI / MyGEOMBase_Helper.hxx
1 // Copyright (C) 2009-2012  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef MYGEOMBASE_HELPER_HXX
21 #define MYGEOMBASE_HELPER_HXX
22
23 #include "GEOM_GEOMBase.hxx"
24 #include "GEOM_GenericObjPtr.h"
25
26 #include <GEOM_Displayer.h>
27 #include <SALOME_ListIO.hxx>
28 #include <SALOMEconfig.h>
29 #include CORBA_CLIENT_HEADER(GEOM_Gen)
30
31 #include <QString>
32 #include <QMap>
33
34 #include <list>
35
36 typedef std::list<GEOM::GEOM_Object_ptr> ObjectList;
37
38 class SalomeApp_Study;
39 class SUIT_Desktop;
40 class SUIT_ViewWindow;
41 class SALOME_Prs;
42 class GEOM_Operation;
43 class TColStd_MapOfInteger;
44
45 //================================================================
46 // Class       : MyGEOMBase_Helper
47 // Description : Helper class for dialog box development, can be used as 
48 //               the second base class for dialog boxes. Contains convenient methods
49 //               performing common operations (display/erase, selection activation,
50 //               publication in a study, transaction management)
51 //================================================================
52 class GEOMBASE_EXPORT MyGEOMBase_Helper
53 {
54 public:
55   MyGEOMBase_Helper( SUIT_Desktop* );
56   virtual ~MyGEOMBase_Helper();
57
58 protected:
59   static GEOM::GEOM_Gen_ptr getGeomEngine();
60
61   void display         ( const ObjectList&, const bool = true );
62   void display         ( GEOM::GEOM_Object_ptr, const bool = true );
63   void erase           ( const ObjectList&, const bool = true );
64   void erase           ( GEOM::GEOM_Object_ptr, const bool = true );
65   void redisplay       ( const ObjectList&, const bool = true, const bool = true );
66   void redisplay       ( GEOM::GEOM_Object_ptr, const bool = true, const bool = true );
67
68   virtual void displayPreview ( const bool   display,
69                                 const bool   activate = false, 
70                                 const bool   update = true,
71                                 const bool   toRemoveFromEngine = true,
72                                 const double lineWidth = -1, 
73                                 const int    displayMode = -1,
74                                 const int    color  = -1 );
75   // This is the easiest way to show preview. It is based on execute() method.
76   // It removes temporary GEOM::GEOM_Objects automatically.
77
78   virtual void displayPreview  ( GEOM::GEOM_Object_ptr obj, 
79                                  const bool   append = false, 
80                                  const bool   activate = false, 
81                                  const bool   update = true,
82                                  const double lineWidth = -1, 
83                                  const int    displayMode = -1,
84                                  const int    color  = -1 );
85   void displayPreview  ( const SALOME_Prs* prs, 
86                          const bool append = false, 
87                          const bool = true );
88   void erasePreview    ( const bool = true );
89
90   void localSelection( const ObjectList&, const int );
91   void localSelection( GEOM::GEOM_Object_ptr, const int );
92   void activate( const int );
93   void globalSelection( const int = GEOM_ALLOBJECTS, const bool = false  );
94   void globalSelection( const TColStd_MapOfInteger&, const bool = false );
95   void globalSelection( const TColStd_MapOfInteger&, const QList<int>& ,const bool = false );
96   void updateViewer    ();
97
98   void prepareSelection( const ObjectList&, const int );
99   void prepareSelection( GEOM::GEOM_Object_ptr, const int );
100
101   QString addInStudy   ( GEOM::GEOM_Object_ptr, const char* theName ); 
102
103   bool openCommand     ();
104   bool abortCommand    ();
105   bool commitCommand   ( const char* = 0 );
106   bool hasCommand      () const;
107
108   void updateObjBrowser() const;
109   int  getStudyId      () const;
110   SalomeApp_Study* getStudy  () const;
111   bool checkViewWindow ();
112
113   bool onAccept( const bool publish = true, const bool useTransaction = true );
114   // This method should be called from "OK" button handler.
115   // <publish> == true means that objects returned by execute() 
116   // should be published in a study.
117
118   void showError();
119   // Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
120   void showError( const QString& msg );
121   // Shows a error message followed by <msg>
122
123   GEOM::GEOM_IOperations_ptr getOperation();
124   // If <myOperation> is nil --> calls createOperation() and put the result
125   // into <myOperation> and returns it;
126   // otherwise, simply returns <myOperation>
127
128   inline void setPrefix( const QString& prefix ) { myPrefix = prefix; }
129   QString getPrefix( GEOM::GEOM_Object_ptr = GEOM::GEOM_Object::_nil() ) const;
130   
131   bool selectObjects( ObjectList& objects );
132   // Selects list of objects 
133
134   ////////////////////////////////////////////////////////////////////////////
135   // Virtual methods, to be redefined in dialog classes
136   ////////////////////////////////////////////////////////////////////////////
137
138   virtual GEOM::GEOM_IOperations_ptr createOperation();
139   // This method should be redefined in dialog boxes so as to return 
140   // proper GEOM_IOperation interface.
141   // Returns nil reference by default
142
143   virtual bool isValid( QString& msg );
144   // Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
145
146   virtual bool execute( ObjectList& objects );
147   // This method is called by onAccept(). 
148   // It should perform the required operation and put all new or modified objects into 
149   // <objects> argument.Should return <false> if some error occurs during its execution. 
150
151   virtual void restoreSubShapes( SALOMEDS::Study_ptr theStudy, SALOMEDS::SObject_ptr theSObject );
152   // This method is called by addInStudy().
153
154   virtual GEOM::GEOM_Object_ptr getFather( GEOM::GEOM_Object_ptr theObj );
155   // This method is called by addInStudy(). It should return a father object
156   // for <theObj> or a nil reference if <theObj> should be published
157   // as a top-level object.
158
159   virtual QString getNewObjectName() const; 
160   virtual bool extractPrefix() const;
161   virtual void addSubshapesToStudy();
162
163   GEOM::GEOM_Object_ptr findObjectInFather( GEOM::GEOM_Object_ptr theFather, const QString& theName );
164   GEOM::GEOM_Object_ptr findObjectInFather( GEOM::GEOM_Object_ptr theFather, int theIndex );
165   // These methods are used to find published sub-object (sub-shape) in the parent object (main shape)
166
167   GEOM::GeomObjPtr        getSelected( TopAbs_ShapeEnum type );
168   GEOM::GeomObjPtr        getSelected( const QList<TopAbs_ShapeEnum>& types );
169   QList<GEOM::GeomObjPtr> getSelected( TopAbs_ShapeEnum type, int count, bool strict = true );
170   QList<GEOM::GeomObjPtr> getSelected( const QList<TopAbs_ShapeEnum>& types, int count, bool strict = true );
171
172   void SetIsPreview(const bool thePreview) {isPreview = thePreview;}
173   bool IsPreview() {return isPreview;}
174
175   GEOM_Displayer*             getDisplayer();
176   SUIT_Desktop*               getDesktop() const;
177
178   virtual void                setIsApplyAndClose( const bool theFlag );
179   virtual bool                isApplyAndClose() const;
180
181   virtual void                setIsOptimizedBrowsing( const bool theFlag );
182   virtual bool                isOptimizedBrowsing() const;
183
184 private:
185   QString                     getEntry( GEOM::GEOM_Object_ptr ) const;
186   void                        clearShapeBuffer( GEOM::GEOM_Object_ptr );
187
188 private:
189   typedef std::list<SALOME_Prs*> PrsList;
190
191   PrsList                     myPreview;
192   GEOM_Displayer*             myDisplayer;
193   GEOM_Operation*             myCommand;
194   GEOM::GEOM_IOperations_var  myOperation;
195   SUIT_ViewWindow*            myViewWindow;
196   QString                     myPrefix;
197   bool                        isPreview;
198   SALOME_ListIO               mySelected;
199   SUIT_Desktop*               myDesktop;
200   bool                        myIsApplyAndClose;
201   bool                        myIsOptimizedBrowsing;
202
203 };
204
205 #endif // GEOMBASE_HELPER_HXX