]> SALOME platform Git repositories - modules/hexablock.git/blob - src/HEXABLOCKGUI/MyGEOMBase_Helper.hxx
Salome HOME
ea3bac841c1d6c2ade846175a2343c3acdc44288
[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   GEOM_Displayer*  getDisplayer();
58   void localSelection( const ObjectList&, const int );
59   void localSelection( GEOM::GEOM_Object_ptr, const int );
60   void globalSelection( const int = GEOM_ALLOBJECTS, const bool = false  );
61   void globalSelection( const TColStd_MapOfInteger&, const bool = false );
62   void globalSelection( const TColStd_MapOfInteger&, const QList<int>& ,const bool = false );
63
64 protected:
65   static GEOM::GEOM_Gen_ptr getGeomEngine();
66
67   void display         ( const ObjectList&, const bool = true );
68   void display         ( GEOM::GEOM_Object_ptr, const bool = true );
69   void erase           ( const ObjectList&, const bool = true );
70   void erase           ( GEOM::GEOM_Object_ptr, const bool = true );
71   void redisplay       ( const ObjectList&, const bool = true, const bool = true );
72   void redisplay       ( GEOM::GEOM_Object_ptr, const bool = true, const bool = true );
73
74   virtual void displayPreview ( const bool   display,
75                                 const bool   activate = false, 
76                                 const bool   update = true,
77                                 const bool   toRemoveFromEngine = true,
78                                 const double lineWidth = -1, 
79                                 const int    displayMode = -1,
80                                 const int    color  = -1 );
81   // This is the easiest way to show preview. It is based on execute() method.
82   // It removes temporary GEOM::GEOM_Objects automatically.
83
84   virtual void displayPreview  ( GEOM::GEOM_Object_ptr obj, 
85                                  const bool   append = false, 
86                                  const bool   activate = false, 
87                                  const bool   update = true,
88                                  const double lineWidth = -1, 
89                                  const int    displayMode = -1,
90                                  const int    color  = -1 );
91   void displayPreview  ( const SALOME_Prs* prs, 
92                          const bool append = false, 
93                          const bool = true );
94   void erasePreview    ( const bool = true );
95
96 //  void localSelection( const ObjectList&, const int );
97 //  void localSelection( GEOM::GEOM_Object_ptr, const int );
98   void activate( const int );
99 //  void globalSelection( const int = GEOM_ALLOBJECTS, const bool = false  );
100 //  void globalSelection( const TColStd_MapOfInteger&, const bool = false );
101 //  void globalSelection( const TColStd_MapOfInteger&, const QList<int>& ,const bool = false );
102   void updateViewer    ();
103
104   void prepareSelection( const ObjectList&, const int );
105   void prepareSelection( GEOM::GEOM_Object_ptr, const int );
106
107   QString addInStudy   ( GEOM::GEOM_Object_ptr, const char* theName ); 
108
109   bool openCommand     ();
110   bool abortCommand    ();
111   bool commitCommand   ( const char* = 0 );
112   bool hasCommand      () const;
113
114   void updateObjBrowser() const;
115   int  getStudyId      () const;
116   SalomeApp_Study* getStudy  () const;
117   bool checkViewWindow ();
118
119   bool onAccept( const bool publish = true, const bool useTransaction = true );
120   // This method should be called from "OK" button handler.
121   // <publish> == true means that objects returned by execute() 
122   // should be published in a study.
123
124   void showError();
125   // Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
126   void showError( const QString& msg );
127   // Shows a error message followed by <msg>
128
129   GEOM::GEOM_IOperations_ptr getOperation();
130   // If <myOperation> is nil --> calls createOperation() and put the result
131   // into <myOperation> and returns it;
132   // otherwise, simply returns <myOperation>
133
134   inline void setPrefix( const QString& prefix ) { myPrefix = prefix; }
135   QString getPrefix( GEOM::GEOM_Object_ptr = GEOM::GEOM_Object::_nil() ) const;
136   
137   bool selectObjects( ObjectList& objects );
138   // Selects list of objects 
139
140   ////////////////////////////////////////////////////////////////////////////
141   // Virtual methods, to be redefined in dialog classes
142   ////////////////////////////////////////////////////////////////////////////
143
144   virtual GEOM::GEOM_IOperations_ptr createOperation();
145   // This method should be redefined in dialog boxes so as to return 
146   // proper GEOM_IOperation interface.
147   // Returns nil reference by default
148
149   virtual bool isValid( QString& msg );
150   // Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
151
152   virtual bool execute( ObjectList& objects );
153   // This method is called by onAccept(). 
154   // It should perform the required operation and put all new or modified objects into 
155   // <objects> argument.Should return <false> if some error occurs during its execution. 
156
157   virtual void restoreSubShapes( SALOMEDS::Study_ptr theStudy, SALOMEDS::SObject_ptr theSObject );
158   // This method is called by addInStudy().
159
160   virtual GEOM::GEOM_Object_ptr getFather( GEOM::GEOM_Object_ptr theObj );
161   // This method is called by addInStudy(). It should return a father object
162   // for <theObj> or a nil reference if <theObj> should be published
163   // as a top-level object.
164
165   virtual QString getNewObjectName() const; 
166   virtual bool extractPrefix() const;
167   virtual void addSubshapesToStudy();
168
169   GEOM::GEOM_Object_ptr findObjectInFather( GEOM::GEOM_Object_ptr theFather, const QString& theName );
170   GEOM::GEOM_Object_ptr findObjectInFather( GEOM::GEOM_Object_ptr theFather, int theIndex );
171   // These methods are used to find published sub-object (sub-shape) in the parent object (main shape)
172
173   GEOM::GeomObjPtr        getSelected( TopAbs_ShapeEnum type );
174   GEOM::GeomObjPtr        getSelected( const QList<TopAbs_ShapeEnum>& types );
175   QList<GEOM::GeomObjPtr> getSelected( TopAbs_ShapeEnum type, int count, bool strict = true );
176   QList<GEOM::GeomObjPtr> getSelected( const QList<TopAbs_ShapeEnum>& types, int count, bool strict = true );
177
178   void SetIsPreview(const bool thePreview) {isPreview = thePreview;}
179   bool IsPreview() {return isPreview;}
180
181 //  GEOM_Displayer*             getDisplayer();
182   SUIT_Desktop*               getDesktop() const;
183
184   virtual void                setIsApplyAndClose( const bool theFlag );
185   virtual bool                isApplyAndClose() const;
186
187   virtual void                setIsOptimizedBrowsing( const bool theFlag );
188   virtual bool                isOptimizedBrowsing() const;
189
190 private:
191   QString                     getEntry( GEOM::GEOM_Object_ptr ) const;
192   void                        clearShapeBuffer( GEOM::GEOM_Object_ptr );
193
194 private:
195   typedef std::list<SALOME_Prs*> PrsList;
196
197   PrsList                     myPreview;
198   GEOM_Displayer*             myDisplayer;
199   GEOM_Operation*             myCommand;
200   GEOM::GEOM_IOperations_var  myOperation;
201   SUIT_ViewWindow*            myViewWindow;
202   QString                     myPrefix;
203   bool                        isPreview;
204   SALOME_ListIO               mySelected;
205   SUIT_Desktop*               myDesktop;
206   bool                        myIsApplyAndClose;
207   bool                        myIsOptimizedBrowsing;
208
209 };
210
211 #endif // GEOMBASE_HELPER_HXX