Salome HOME
64dbd4d222c7804f12d030c2424ab13afbfd84c8
[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 <SALOMEconfig.h>
35 #include CORBA_CLIENT_HEADER(GEOM_Gen)
36
37 #include <qstring.h>
38
39 #include <list>
40
41 typedef std::list<GEOM::GEOM_Object_ptr> ObjectList;
42
43 class GEOM_Operation;
44 class QAD_Study;
45 class TopoDS_Shape;
46 class QAD_ViewFrame;
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_Helper
57 {
58 public:
59   GEOMBase_Helper();
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   // This is the easiest way to show preview. It is based on execute() method.
77   // It removes temporary GEOM::GEOM_Objects automatically.
78
79   virtual void displayPreview  ( GEOM::GEOM_Object_ptr obj, 
80                                  const bool   append = false, 
81                                  const bool   activate = false, 
82                                  const bool   update = true,
83                                  const double lineWidth = -1 );
84   void displayPreview  ( const SALOME_Prs* prs, 
85                          const bool append = false, 
86                          const bool = true );
87   void erasePreview    ( const bool = true );
88
89   void localSelection( const ObjectList&, const int );
90   void localSelection( GEOM::GEOM_Object_ptr, const int );
91   void activate( const int );
92   void globalSelection( const int = GEOM_ALLOBJECTS, const bool = false  );
93   void globalSelection( const TColStd_MapOfInteger&, const bool = false );
94   void updateViewer    ();
95
96   void prepareSelection( const ObjectList&, const int );
97   void prepareSelection( GEOM::GEOM_Object_ptr, const int );
98
99   void addInStudy      ( GEOM::GEOM_Object_ptr, const char* theName ); 
100
101   bool openCommand     ();
102   bool abortCommand    ();
103   bool commitCommand   ( const char* = 0 );
104   bool hasCommand      () const;
105
106   void updateObjBrowser() const;
107   int  getStudyId      () const;
108   QAD_Study* getStudy  () const;
109   bool checkViewFrame  ();
110
111   bool onAccept( const bool publish = true, const bool useTransaction = true );
112   // This method should be called from "OK" button handler.
113   // <publish> == true means that objects returned by execute() 
114   // should be published in a study.
115
116   void showError();
117   // Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
118   void showError( const QString& msg );
119   // Shows a error message followed by <msg>
120
121   GEOM::GEOM_IOperations_ptr getOperation();
122   // If <myOperation> is nil --> calls createOperation() and put the result
123   // into <myOperation> and returns it;
124   // otherwise, simply returns <myOperation>
125
126   inline void setPrefix( const QString& prefix ) { myPrefix = prefix; }
127   QString getPrefix( GEOM::GEOM_Object_ptr = GEOM::GEOM_Object::_nil() ) const;
128
129   ////////////////////////////////////////////////////////////////////////////
130   // Virtual methods, to be redefined in dialog classes
131   ////////////////////////////////////////////////////////////////////////////
132
133   virtual GEOM::GEOM_IOperations_ptr createOperation();
134   // This method should be redefined in dialog boxes so as to return 
135   // proper GEOM_IOperation interface.
136   // Returns nil reference by default
137
138   virtual bool isValid( QString& msg );
139   // Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
140
141   virtual bool execute( ObjectList& objects );
142   // This method is called by onAccept(). 
143   // It should perform the required operation and put all new or modified objects into 
144   // <objects> argument.Should return <false> if some error occurs during its execution. 
145
146   virtual GEOM::GEOM_Object_ptr getFather( GEOM::GEOM_Object_ptr theObj );
147   // This method is called by addInStudy(). It should return a father object
148   // for <theObj> or a nil reference if <theObj> should be published
149   // as a top-level object.
150
151   virtual const char* getNewObjectName() const; 
152
153   void SetIsPreview(const bool thePreview) {isPreview = thePreview;}
154   bool IsPreview() {return isPreview;}
155
156   GEOM_Displayer*             getDisplayer();
157
158 private:
159   char* getEntry              ( GEOM::GEOM_Object_ptr ) const;
160   void                        clearShapeBuffer( GEOM::GEOM_Object_ptr );
161
162 private:
163   typedef std::list<SALOME_Prs*> PrsList;
164
165   PrsList                     myPreview;
166   GEOM_Displayer*             myDisplayer;
167   GEOM_Operation*             myCommand;
168   GEOM::GEOM_IOperations_var  myOperation;
169   QAD_ViewFrame*              myViewFrame;
170   QString                     myPrefix;
171   bool                        isPreview;
172
173 };
174
175 #endif