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