1 // Copyright (C) 2009-2012 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef MYGEOMBASE_HELPER_HXX
21 #define MYGEOMBASE_HELPER_HXX
23 #include "GEOM_GEOMBase.hxx"
24 #include "GEOM_GenericObjPtr.h"
26 #include <GEOM_Displayer.h>
27 #include <SALOME_ListIO.hxx>
28 #include <SALOMEconfig.h>
29 #include <SUIT_ViewWindow.h>
30 #include CORBA_CLIENT_HEADER(GEOM_Gen)
37 typedef std::list<GEOM::GEOM_Object_ptr> ObjectList;
39 class SalomeApp_Study;
41 class SUIT_ViewWindow;
44 class TColStd_MapOfInteger;
46 //================================================================
47 // Class : MyGEOMBase_Helper
48 // Description : Helper class for dialog box development, can be used as
49 // the second base class for dialog boxes. Contains convenient methods
50 // performing common operations (display/erase, selection activation,
51 // publication in a study, transaction management)
52 //================================================================
53 class GEOMBASE_EXPORT MyGEOMBase_Helper
56 MyGEOMBase_Helper( SUIT_Desktop* );
57 virtual ~MyGEOMBase_Helper();
58 GEOM_Displayer* getDisplayer();
59 void localSelection( const ObjectList&, const int );
60 void localSelection( GEOM::GEOM_Object_ptr, const int );
61 void globalSelection( const int = GEOM_ALLOBJECTS, const bool = false );
62 void globalSelection( const TColStd_MapOfInteger&, const bool = false );
63 void globalSelection( const TColStd_MapOfInteger&, const QList<int>& ,const bool = false );
64 void erasePreview ( const bool = true );
65 void display ( GEOM::GEOM_Object_ptr, const bool = true );
66 QString addInStudy ( GEOM::GEOM_Object_ptr, const char* theName );
68 void localSelection(SUIT_ViewWindow *view, const int theMode);
69 void globalSelection( SUIT_ViewWindow *view, const bool update = false );
72 static GEOM::GEOM_Gen_ptr getGeomEngine();
74 void display ( const ObjectList&, const bool = true );
75 // void display ( GEOM::GEOM_Object_ptr, const bool = true );
76 void erase ( const ObjectList&, const bool = true );
77 void erase ( GEOM::GEOM_Object_ptr, const bool = true );
78 void redisplay ( const ObjectList&, const bool = true, const bool = true );
79 void redisplay ( GEOM::GEOM_Object_ptr, const bool = true, const bool = true );
81 virtual void displayPreview ( const bool display,
82 const bool activate = false,
83 const bool update = true,
84 const bool toRemoveFromEngine = true,
85 const double lineWidth = -1,
86 const int displayMode = -1,
87 const int color = -1 );
88 // This is the easiest way to show preview. It is based on execute() method.
89 // It removes temporary GEOM::GEOM_Objects automatically.
91 virtual void displayPreview ( GEOM::GEOM_Object_ptr obj,
92 const bool append = false,
93 const bool activate = false,
94 const bool update = true,
95 const double lineWidth = -1,
96 const int displayMode = -1,
97 const int color = -1 );
98 void displayPreview ( const SALOME_Prs* prs,
99 const bool append = false,
102 // void localSelection( const ObjectList&, const int );
103 // void localSelection( GEOM::GEOM_Object_ptr, const int );
104 void activate( const int );
105 // void globalSelection( const int = GEOM_ALLOBJECTS, const bool = false );
106 // void globalSelection( const TColStd_MapOfInteger&, const bool = false );
107 // void globalSelection( const TColStd_MapOfInteger&, const QList<int>& ,const bool = false );
108 void updateViewer ();
110 void prepareSelection( const ObjectList&, const int );
111 void prepareSelection( GEOM::GEOM_Object_ptr, const int );
113 // QString addInStudy ( GEOM::GEOM_Object_ptr, const char* theName );
116 bool abortCommand ();
117 bool commitCommand ( const char* = 0 );
118 bool hasCommand () const;
120 void updateObjBrowser() const;
121 int getStudyId () const;
122 SalomeApp_Study* getStudy () const;
123 bool checkViewWindow ();
125 bool onAccept( const bool publish = true, const bool useTransaction = true );
126 // This method should be called from "OK" button handler.
127 // <publish> == true means that objects returned by execute()
128 // should be published in a study.
131 // Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
132 void showError( const QString& msg );
133 // Shows a error message followed by <msg>
135 GEOM::GEOM_IOperations_ptr getOperation();
136 // If <myOperation> is nil --> calls createOperation() and put the result
137 // into <myOperation> and returns it;
138 // otherwise, simply returns <myOperation>
140 inline void setPrefix( const QString& prefix ) { myPrefix = prefix; }
141 QString getPrefix( GEOM::GEOM_Object_ptr = GEOM::GEOM_Object::_nil() ) const;
143 bool selectObjects( ObjectList& objects );
144 // Selects list of objects
146 ////////////////////////////////////////////////////////////////////////////
147 // Virtual methods, to be redefined in dialog classes
148 ////////////////////////////////////////////////////////////////////////////
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
155 virtual bool isValid( QString& msg );
156 // Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
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.
163 virtual void restoreSubShapes( SALOMEDS::Study_ptr theStudy, SALOMEDS::SObject_ptr theSObject );
164 // This method is called by addInStudy().
166 virtual GEOM::GEOM_Object_ptr getFather( GEOM::GEOM_Object_ptr theObj );
167 // This method is called by addInStudy(). It should return a father object
168 // for <theObj> or a nil reference if <theObj> should be published
169 // as a top-level object.
171 virtual QString getNewObjectName() const;
172 virtual bool extractPrefix() const;
173 virtual void addSubshapesToStudy();
175 GEOM::GEOM_Object_ptr findObjectInFather( GEOM::GEOM_Object_ptr theFather, const QString& theName );
176 GEOM::GEOM_Object_ptr findObjectInFather( GEOM::GEOM_Object_ptr theFather, int theIndex );
177 // These methods are used to find published sub-object (sub-shape) in the parent object (main shape)
179 GEOM::GeomObjPtr getSelected( TopAbs_ShapeEnum type );
180 GEOM::GeomObjPtr getSelected( const QList<TopAbs_ShapeEnum>& types );
181 QList<GEOM::GeomObjPtr> getSelected( TopAbs_ShapeEnum type, int count, bool strict = true );
182 QList<GEOM::GeomObjPtr> getSelected( const QList<TopAbs_ShapeEnum>& types, int count, bool strict = true );
184 void SetIsPreview(const bool thePreview) {isPreview = thePreview;}
185 bool IsPreview() {return isPreview;}
187 // GEOM_Displayer* getDisplayer();
188 SUIT_Desktop* getDesktop() const;
190 virtual void setIsApplyAndClose( const bool theFlag );
191 virtual bool isApplyAndClose() const;
193 virtual void setIsOptimizedBrowsing( const bool theFlag );
194 virtual bool isOptimizedBrowsing() const;
197 QString getEntry( GEOM::GEOM_Object_ptr ) const;
198 void clearShapeBuffer( GEOM::GEOM_Object_ptr );
201 typedef std::list<SALOME_Prs*> PrsList;
204 GEOM_Displayer* myDisplayer;
205 GEOM_Operation* myCommand;
206 GEOM::GEOM_IOperations_var myOperation;
207 SUIT_ViewWindow* myViewWindow;
210 SALOME_ListIO mySelected;
211 SUIT_Desktop* myDesktop;
212 bool myIsApplyAndClose;
213 bool myIsOptimizedBrowsing;
217 #endif // GEOMBASE_HELPER_HXX