]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMBase/GEOMBase_Helper.h
Salome HOME
5bafde6ff718546b202ebe6b368e8e2d01c57fe6
[modules/geom.git] / src / GEOMBase / GEOMBase_Helper.h
1 // Copyright (C) 2007-2013  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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : GEOMBase_Helper.h
25 // Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
26
27 #ifndef GEOMBASE_HELPER_H
28 #define GEOMBASE_HELPER_H
29
30 #include "GEOM_GEOMBase.hxx"
31 #include "GEOM_GenericObjPtr.h"
32
33 #include <GEOM_Displayer.h>
34 #include <SALOME_ListIO.hxx>
35 #include <SALOMEconfig.h>
36 #include CORBA_CLIENT_HEADER(GEOM_Gen)
37
38 #include <QString>
39 #include <QMap>
40
41 #include <list>
42
43 typedef std::list<GEOM::GEOM_Object_ptr> ObjectList;
44
45 class SalomeApp_Study;
46 class SUIT_Desktop;
47 class SUIT_ViewWindow;
48 class SALOME_Prs;
49 class GEOM_Operation;
50 class TColStd_MapOfInteger;
51
52 //================================================================
53 // Class       : GEOMBase_Helper
54 // Description : Helper class for dialog box development, can be used as
55 //               the second base class for dialog boxes. Contains convenient methods
56 //               performing common operations (display/erase, selection activation,
57 //               publication in a study, transaction management)
58 //================================================================
59 class GEOMBASE_EXPORT GEOMBase_Helper
60 {
61 public:
62   GEOMBase_Helper( SUIT_Desktop* );
63   virtual ~GEOMBase_Helper();
64   static SUIT_ViewWindow* getActiveView();
65
66 protected:
67   static GEOM::GEOM_Gen_ptr getGeomEngine();
68
69   void display         ( const ObjectList&, const bool = true );
70   void display         ( GEOM::GEOM_Object_ptr, const bool = true );
71   void erase           ( const ObjectList&, const bool = true );
72   void erase           ( GEOM::GEOM_Object_ptr, const bool = true );
73   void redisplay       ( const ObjectList&, const bool = true, const bool = true );
74   void redisplay       ( GEOM::GEOM_Object_ptr, const bool = true, const bool = true );
75
76   virtual void displayPreview ( const bool   display,
77                                 const bool   activate = false,
78                                 const bool   update = true,
79                                 const bool   toRemoveFromEngine = true,
80                                 const double lineWidth = -1,
81                                 const int    displayMode = -1,
82                                 const int    color  = -1 );
83   // This is the easiest way to show preview. It is based on execute() method.
84   // It removes temporary GEOM::GEOM_Objects automatically.
85
86   virtual void displayPreview  ( GEOM::GEOM_Object_ptr obj,
87                                  const bool   append = false,
88                                  const bool   activate = false,
89                                  const bool   update = true,
90                                  const double lineWidth = -1,
91                                  const int    displayMode = -1,
92                                  const int    color  = -1 );
93   void displayPreview  ( const SALOME_Prs* prs,
94                          const bool append = false,
95                          const bool = true );
96   void erasePreview    ( const bool = true );
97
98   void localSelection( const ObjectList&, const int );
99   void localSelection( GEOM::GEOM_Object_ptr, const int );
100   void activate( const int );
101   void globalSelection( const int = GEOM_ALLOBJECTS, const bool = false  );
102   void globalSelection( const TColStd_MapOfInteger&, const bool = false );
103   void globalSelection( const TColStd_MapOfInteger&, const QList<int>& ,const bool = false );
104   void updateViewer    ();
105
106   void prepareSelection( const ObjectList&, const int );
107   void prepareSelection( GEOM::GEOM_Object_ptr, const int );
108
109   QString addInStudy   ( GEOM::GEOM_Object_ptr, const char* theName );
110
111   bool openCommand     ();
112   bool abortCommand    ();
113   bool commitCommand   ( const char* = 0 );
114   bool hasCommand      () const;
115
116   void updateObjBrowser() const;
117   int  getStudyId      () const;
118   SalomeApp_Study* getStudy  () const;
119   bool checkViewWindow ();
120
121   bool onAccept( const bool publish = true, const bool useTransaction = true, bool erasePreviewFlag = true);
122   // This method should be called from "OK" button handler.
123   // <publish> == true means that objects returned by execute()
124   // should be published in a study.
125
126   void showError();
127   // Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
128   void showError( const QString& msg );
129   // Shows a error message followed by <msg>
130
131   GEOM::GEOM_IOperations_ptr getOperation();
132   // If <myOperation> is nil --> calls createOperation() and put the result
133   // into <myOperation> and returns it;
134   // otherwise, simply returns <myOperation>
135
136   inline void setPrefix( const QString& prefix ) { myPrefix = prefix; }
137   QString getPrefix( GEOM::GEOM_Object_ptr = GEOM::GEOM_Object::_nil() ) const;
138
139   bool selectObjects( ObjectList& objects );
140   // Selects list of objects
141
142   ////////////////////////////////////////////////////////////////////////////
143   // Virtual methods, to be redefined in dialog classes
144   ////////////////////////////////////////////////////////////////////////////
145
146   virtual GEOM::GEOM_IOperations_ptr createOperation();
147   // This method should be redefined in dialog boxes so as to return
148   // proper GEOM_IOperation interface.
149   // Returns nil reference by default
150
151   virtual bool isValid( QString& msg );
152   // Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
153
154   virtual bool execute( ObjectList& objects );
155   // This method is called by onAccept().
156   // It should perform the required operation and put all new or modified objects into
157   // <objects> argument.Should return <false> if some error occurs during its execution.
158
159   virtual void restoreSubShapes( SALOMEDS::Study_ptr theStudy, SALOMEDS::SObject_ptr theSObject );
160   // This method is called by addInStudy().
161
162   virtual GEOM::GEOM_Object_ptr getFather( GEOM::GEOM_Object_ptr theObj );
163   // This method is called by addInStudy(). It should return a father object
164   // for <theObj> or a nil reference if <theObj> should be published
165   // as a top-level object.
166
167   virtual QString getNewObjectName (int CurrObj = -1) const;
168   virtual QString getObjectName(GEOM::GEOM_Object_ptr object) const;
169   virtual bool extractPrefix() const;
170   virtual void addSubshapesToStudy();
171
172   GEOM::GEOM_Object_ptr findObjectInFather( GEOM::GEOM_Object_ptr theFather, const QString& theName );
173   GEOM::GEOM_Object_ptr findObjectInFather( GEOM::GEOM_Object_ptr theFather, int theIndex );
174   // These methods are used to find published sub-object (sub-shape) in the parent object (main shape)
175
176   GEOM::GeomObjPtr        getSelected( TopAbs_ShapeEnum type );
177   GEOM::GeomObjPtr        getSelected( const QList<TopAbs_ShapeEnum>& types );
178   QList<GEOM::GeomObjPtr> getSelected( TopAbs_ShapeEnum type, int count, bool strict = true );
179   QList<GEOM::GeomObjPtr> getSelected( const QList<TopAbs_ShapeEnum>& types, int count, bool strict = true );
180
181   void SetIsPreview(const bool thePreview) {isPreview = thePreview;}
182   bool IsPreview() {return isPreview;}
183
184   GEOM_Displayer*             getDisplayer();
185   SUIT_Desktop*               getDesktop() const;
186
187   virtual void                setIsApplyAndClose( const bool theFlag );
188   virtual bool                isApplyAndClose() const;
189
190   virtual void                setIsOptimizedBrowsing( const bool theFlag );
191   virtual bool                isOptimizedBrowsing() const;
192
193   virtual void                setIsWaitCursorEnabled( const bool theFlag ) {myIsWaitCursorEnabled = theFlag;}
194   virtual bool                isWaitCursorEnabled() const {return myIsWaitCursorEnabled ;}
195   virtual void                setIsDisableBrowsing( const bool theFlag ) { myIsDisableBrowsing = theFlag; }
196   virtual bool                isDisableBrowsing() const { return myIsDisableBrowsing; }
197   virtual void                setIsDisplayResult( const bool theFlag ) {myIsDisplayResult = theFlag; }
198   virtual bool                isDisplayResult() const { return myIsDisplayResult; }
199
200 private:
201   QString                     getEntry( GEOM::GEOM_Object_ptr ) const;
202   void                        clearShapeBuffer( GEOM::GEOM_Object_ptr );
203
204 private:
205   typedef std::list<SALOME_Prs*> PrsList;
206
207   PrsList                     myPreview;
208   GEOM_Displayer*             myDisplayer;
209   GEOM_Operation*             myCommand;
210   GEOM::GEOM_IOperations_var  myOperation;
211   SUIT_ViewWindow*            myViewWindow;
212   QString                     myPrefix;
213   bool                        isPreview;
214   SALOME_ListIO               mySelected;
215   SUIT_Desktop*               myDesktop;
216   bool                        myIsApplyAndClose;
217   bool                        myIsOptimizedBrowsing;
218   bool                        myIsWaitCursorEnabled;
219   bool                        myIsDisableBrowsing;  //This flag enable/disable selection
220                                                     //in the Object Browser newly created objects.
221   bool                        myIsDisplayResult;    //This flag display/hide newly created objects.
222 };
223
224 #endif // GEOMBASE_HELPER_H