Salome HOME
getDesktop() method is changed: now it is NOT virtual, it is implemented in GEOMBase_...
[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.org 
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
42 typedef std::list<GEOM::GEOM_Object_ptr> ObjectList;
43
44 class SalomeApp_Study;
45 class SUIT_Desktop;
46 class SUIT_ViewWindow;
47 class GEOM_Operation;
48 class TopoDS_Shape;
49 class TColStd_MapOfInteger;
50
51 //================================================================
52 // Class       : GEOMBase_Helper
53 // Description : Helper class for dialog box development, can be used as 
54 //               the second base class for dialog boxes. Contains convenient methods
55 //               performing common operations (display/erase, selection activation,
56 //               publication in a study, transaction management)
57 //================================================================
58 class GEOMBase_Helper
59 {
60 public:
61   GEOMBase_Helper( SUIT_Desktop* );
62   virtual ~GEOMBase_Helper();
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   activate = false, 
75                                 const bool   update = true,
76                                 const bool   toRemoveFromEngine = true,
77                                 const double lineWidth = -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   void displayPreview  ( const SALOME_Prs* prs, 
87                          const bool append = false, 
88                          const bool = true );
89   void erasePreview    ( const bool = true );
90
91   void localSelection( const ObjectList&, const int );
92   void localSelection( GEOM::GEOM_Object_ptr, const int );
93   void activate( const int );
94   void globalSelection( const int = GEOM_ALLOBJECTS, const bool = false  );
95   void globalSelection( const TColStd_MapOfInteger&, const bool = false );
96   void updateViewer    ();
97
98   void prepareSelection( const ObjectList&, const int );
99   void prepareSelection( GEOM::GEOM_Object_ptr, const int );
100
101   void addInStudy      ( GEOM::GEOM_Object_ptr, const char* theName ); 
102
103   bool openCommand     ();
104   bool abortCommand    ();
105   bool commitCommand   ( const char* = 0 );
106   bool hasCommand      () const;
107
108   void updateObjBrowser() const;
109   int  getStudyId      () const;
110   SalomeApp_Study* getStudy  () const;
111   bool checkViewWindow ();
112
113   bool onAccept( const bool publish = true, const bool useTransaction = true );
114   // This method should be called from "OK" button handler.
115   // <publish> == true means that objects returned by execute() 
116   // should be published in a study.
117
118   void showError();
119   // Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
120   void showError( const QString& msg );
121   // Shows a error message followed by <msg>
122
123   GEOM::GEOM_IOperations_ptr getOperation();
124   // If <myOperation> is nil --> calls createOperation() and put the result
125   // into <myOperation> and returns it;
126   // otherwise, simply returns <myOperation>
127
128   inline void setPrefix( const QString& prefix ) { myPrefix = prefix; }
129   QString getPrefix( GEOM::GEOM_Object_ptr = GEOM::GEOM_Object::_nil() ) const;
130
131   const SALOME_ListIO& selectedIO();
132   // Function returns a list of SALOME_InteractiveObject's from
133   // selection manager in GUI
134
135   int   IObjectCount() ;
136   // Function returns the number of selected objects
137   
138   Handle(SALOME_InteractiveObject) firstIObject() ;
139   // Function returns the first selected object in the list
140   // of selected objects
141
142   Handle(SALOME_InteractiveObject) lastIObject() ;
143   // Function returns the last selected object in the list
144   // of selected 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 GEOM::GEOM_Object_ptr getFather( GEOM::GEOM_Object_ptr theObj );
164   // This method is called by addInStudy(). It should return a father object
165   // for <theObj> or a nil reference if <theObj> should be published
166   // as a top-level object.
167
168   virtual const char* getNewObjectName() const; 
169
170   void SetIsPreview(const bool thePreview) {isPreview = thePreview;}
171   bool IsPreview() {return isPreview;}
172
173   GEOM_Displayer*             getDisplayer();
174   SUIT_Desktop*               getDesktop() const;
175
176 private:
177   char* getEntry              ( GEOM::GEOM_Object_ptr ) const;
178   void                        clearShapeBuffer( GEOM::GEOM_Object_ptr );
179
180 private:
181   typedef std::list<SALOME_Prs*> PrsList;
182
183   PrsList                     myPreview;
184   GEOM_Displayer*             myDisplayer;
185   GEOM_Operation*             myCommand;
186   GEOM::GEOM_IOperations_var  myOperation;
187   SUIT_ViewWindow*            myViewWindow;
188   QString                     myPrefix;
189   bool                        isPreview;
190   SALOME_ListIO               mySelected;
191   SUIT_Desktop*               myDesktop;
192
193 };
194
195 #endif