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