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