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