Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[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 //
23 //
24 //  File   : GEOMBase_Helper.h
25 //  Author : Sergey ANIKIN
26 //  Module : GEOM
27 //  $Header$
28
29 #ifndef GEOMBASE_HELPER_H
30 #define GEOMBASE_HELPER_H
31
32 #include "GEOM_Displayer.h"
33 #include "SALOME_Prs.h"
34 #include "SALOME_ListIO.hxx"
35 #include <SALOMEconfig.h>
36 #include CORBA_CLIENT_HEADER(GEOM_Gen)
37
38 #include <qstring.h>
39
40 #include <list>
41 //#if defined WNT 
42 //#include <SALOME_WNT.hxx>
43 //#else
44 //#define SALOME_WNT_EXPORT
45 //#endif
46 #if defined WNT && defined WIN32 && defined SALOME_WNT_EXPORTS
47 #define GEOMBASE_WNT_EXPORT __declspec( dllexport )
48 #else
49 #define GEOMBASE_WNT_EXPORT
50 #endif
51 typedef std::list<GEOM::GEOM_Object_ptr> ObjectList;
52
53 class SalomeApp_Study;
54 class SUIT_Desktop;
55 class SUIT_ViewWindow;
56 class GEOM_Operation;
57 class TopoDS_Shape;
58 class TColStd_MapOfInteger;
59
60 //================================================================
61 // Class       : GEOMBase_Helper
62 // Description : Helper class for dialog box development, can be used as 
63 //               the second base class for dialog boxes. Contains convenient methods
64 //               performing common operations (display/erase, selection activation,
65 //               publication in a study, transaction management)
66 //================================================================
67 class GEOMBASE_WNT_EXPORT GEOMBase_Helper
68 {
69 public:
70   GEOMBase_Helper( SUIT_Desktop* );
71   virtual ~GEOMBase_Helper();
72
73 protected:
74   static GEOM::GEOM_Gen_ptr getGeomEngine();
75
76   void display         ( const ObjectList&, const bool = true );
77   void display         ( GEOM::GEOM_Object_ptr, const bool = true );
78   void erase           ( const ObjectList&, const bool = true );
79   void erase           ( GEOM::GEOM_Object_ptr, const bool = true );
80   void redisplay       ( const ObjectList&, const bool = true, const bool = true );
81   void redisplay       ( GEOM::GEOM_Object_ptr, const bool = true, const bool = true );
82
83   virtual void displayPreview ( const bool   activate = false, 
84                                 const bool   update = true,
85                                 const bool   toRemoveFromEngine = true,
86                                 const double lineWidth = -1 );
87   // This is the easiest way to show preview. It is based on execute() method.
88   // It removes temporary GEOM::GEOM_Objects automatically.
89
90   virtual void displayPreview  ( GEOM::GEOM_Object_ptr obj, 
91                                  const bool   append = false, 
92                                  const bool   activate = false, 
93                                  const bool   update = true,
94                                  const double lineWidth = -1 );
95   void displayPreview  ( const SALOME_Prs* prs, 
96                          const bool append = false, 
97                          const bool = true );
98   void erasePreview    ( const bool = true );
99
100   void localSelection( const ObjectList&, const int );
101   void localSelection( GEOM::GEOM_Object_ptr, const int );
102   void activate( const int );
103   void globalSelection( const int = GEOM_ALLOBJECTS, const bool = false  );
104   void globalSelection( const TColStd_MapOfInteger&, const bool = false );
105   void updateViewer    ();
106
107   void prepareSelection( const ObjectList&, const int );
108   void prepareSelection( GEOM::GEOM_Object_ptr, const int );
109
110   void addInStudy      ( GEOM::GEOM_Object_ptr, const char* theName ); 
111
112   bool openCommand     ();
113   bool abortCommand    ();
114   bool commitCommand   ( const char* = 0 );
115   bool hasCommand      () const;
116
117   void updateObjBrowser() const;
118   int  getStudyId      () const;
119   SalomeApp_Study* getStudy  () const;
120   bool checkViewWindow ();
121
122   bool onAccept( const bool publish = true, const bool useTransaction = true );
123   // This method should be called from "OK" button handler.
124   // <publish> == true means that objects returned by execute() 
125   // should be published in a study.
126
127   void showError();
128   // Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
129   void showError( const QString& msg );
130   // Shows a error message followed by <msg>
131
132   GEOM::GEOM_IOperations_ptr getOperation();
133   // If <myOperation> is nil --> calls createOperation() and put the result
134   // into <myOperation> and returns it;
135   // otherwise, simply returns <myOperation>
136
137   inline void setPrefix( const QString& prefix ) { myPrefix = prefix; }
138   QString getPrefix( GEOM::GEOM_Object_ptr = GEOM::GEOM_Object::_nil() ) const;
139
140   const SALOME_ListIO& selectedIO();
141   // Function returns a list of SALOME_InteractiveObject's from
142   // selection manager in GUI
143
144   int   IObjectCount() ;
145   // Function returns the number of selected objects
146   
147   Handle(SALOME_InteractiveObject) firstIObject() ;
148   // Function returns the first selected object in the list
149   // of selected objects
150
151   Handle(SALOME_InteractiveObject) lastIObject() ;
152   // Function returns the last selected object in the list
153   // of selected objects
154
155   ////////////////////////////////////////////////////////////////////////////
156   // Virtual methods, to be redefined in dialog classes
157   ////////////////////////////////////////////////////////////////////////////
158
159   virtual GEOM::GEOM_IOperations_ptr createOperation();
160   // This method should be redefined in dialog boxes so as to return 
161   // proper GEOM_IOperation interface.
162   // Returns nil reference by default
163
164   virtual bool isValid( QString& msg );
165   // Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
166
167   virtual bool execute( ObjectList& objects );
168   // This method is called by onAccept(). 
169   // It should perform the required operation and put all new or modified objects into 
170   // <objects> argument.Should return <false> if some error occurs during its execution. 
171
172   virtual GEOM::GEOM_Object_ptr getFather( GEOM::GEOM_Object_ptr theObj );
173   // This method is called by addInStudy(). It should return a father object
174   // for <theObj> or a nil reference if <theObj> should be published
175   // as a top-level object.
176
177   virtual const char* getNewObjectName() const; 
178
179   void SetIsPreview(const bool thePreview) {isPreview = thePreview;}
180   bool IsPreview() {return isPreview;}
181
182   GEOM_Displayer*             getDisplayer();
183   SUIT_Desktop*               getDesktop() const;
184
185 private:
186   char* getEntry              ( GEOM::GEOM_Object_ptr ) const;
187   void                        clearShapeBuffer( GEOM::GEOM_Object_ptr );
188
189 private:
190   typedef std::list<SALOME_Prs*> PrsList;
191
192   PrsList                     myPreview;
193   GEOM_Displayer*             myDisplayer;
194   GEOM_Operation*             myCommand;
195   GEOM::GEOM_IOperations_var  myOperation;
196   SUIT_ViewWindow*            myViewWindow;
197   QString                     myPrefix;
198   bool                        isPreview;
199   SALOME_ListIO               mySelected;
200   SUIT_Desktop*               myDesktop;
201
202 };
203
204 #endif