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