1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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)
27 #ifndef GEOMBASE_HELPER_H
28 #define GEOMBASE_HELPER_H
30 #include "GEOM_GEOMBase.hxx"
31 #include "GEOM_GenericObjPtr.h"
33 #include <GEOM_Displayer.h>
34 #include <SALOME_ListIO.hxx>
35 #include <SALOMEconfig.h>
36 #include CORBA_CLIENT_HEADER(GEOM_Gen)
43 typedef std::list<GEOM::GEOM_Object_ptr> ObjectList;
45 class SalomeApp_Study;
47 class SUIT_ViewWindow;
50 class TColStd_MapOfInteger;
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
62 GEOMBase_Helper( SUIT_Desktop* );
63 virtual ~GEOMBase_Helper();
64 static SUIT_ViewWindow* getActiveView();
67 static GEOM::GEOM_Gen_ptr getGeomEngine();
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 );
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,
83 const bool append = false );
84 // This is the easiest way to show preview. It is based on execute() method.
85 // It removes temporary GEOM::GEOM_Objects automatically.
87 virtual void displayPreview ( GEOM::GEOM_Object_ptr obj,
88 const bool append = false,
89 const bool activate = false,
90 const bool update = true,
91 const double lineWidth = -1,
92 const int displayMode = -1,
93 const int color = -1 );
94 void displayPreview ( const SALOME_Prs* prs,
95 const bool append = false,
97 void erasePreview ( const bool = true );
99 void localSelection( const ObjectList&, const std::list<int> );
100 void localSelection( const ObjectList&, const int );
101 void localSelection( GEOM::GEOM_Object_ptr, const std::list<int> );
102 void localSelection( GEOM::GEOM_Object_ptr, const int );
103 void localSelection( const std::list<int> );
104 void localSelection( const int );
105 void activate( const int );
106 void globalSelection( const int = GEOM_ALLOBJECTS, const bool = false );
107 void globalSelection( const TColStd_MapOfInteger&, const bool = false );
108 void globalSelection( const TColStd_MapOfInteger&, const QList<int>& ,const bool = false );
109 void updateViewer ();
111 void prepareSelection( const ObjectList&, const int );
112 void prepareSelection( GEOM::GEOM_Object_ptr, const int );
114 QString addInStudy ( GEOM::GEOM_Object_ptr, const char* theName );
117 bool abortCommand ();
118 bool commitCommand ( const char* = 0 );
119 bool hasCommand () const;
121 void updateObjBrowser() const;
122 int getStudyId () const;
123 SalomeApp_Study* getStudy () const;
124 bool checkViewWindow ();
126 bool onAccept( const bool publish = true, const bool useTransaction = true, bool erasePreviewFlag = true);
127 // This method should be called from "OK" button handler.
128 // <publish> == true means that objects returned by execute()
129 // should be published in a study.
132 // Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
133 void showError( const QString& msg );
134 // Shows a error message followed by <msg>
136 GEOM::GEOM_IOperations_ptr getOperation();
137 // If <myOperation> is nil --> calls createOperation() and put the result
138 // into <myOperation> and returns it;
139 // otherwise, simply returns <myOperation>
141 inline void setPrefix( const QString& prefix ) { myPrefix = prefix; }
142 QString getPrefix( GEOM::GEOM_Object_ptr = GEOM::GEOM_Object::_nil() ) const;
144 bool selectObjects( ObjectList& objects );
145 // Selects list of objects
147 ////////////////////////////////////////////////////////////////////////////
148 // Virtual methods, to be redefined in dialog classes
149 ////////////////////////////////////////////////////////////////////////////
151 virtual GEOM::GEOM_IOperations_ptr createOperation();
152 // This method should be redefined in dialog boxes so as to return
153 // proper GEOM_IOperation interface.
154 // Returns nil reference by default
156 virtual bool isValid( QString& msg );
157 // Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
159 virtual bool execute( ObjectList& objects );
160 // This method is called by onAccept().
161 // It should perform the required operation and put all new or modified objects into
162 // <objects> argument.Should return <false> if some error occurs during its execution.
164 virtual void restoreSubShapes( SALOMEDS::Study_ptr theStudy, SALOMEDS::SObject_ptr theSObject );
165 // This method is called by addInStudy().
167 virtual GEOM::GEOM_Object_ptr getFather( GEOM::GEOM_Object_ptr theObj );
168 // This method is called by addInStudy(). It should return a father object
169 // for <theObj> or a nil reference if <theObj> should be published
170 // as a top-level object.
172 virtual QString getNewObjectName (int CurrObj = -1) const;
173 virtual QString getObjectName(GEOM::GEOM_Object_ptr object) const;
174 virtual bool extractPrefix() const;
175 virtual void addSubshapesToStudy();
176 virtual QList<GEOM::GeomObjPtr> getSourceObjects();
178 GEOM::GEOM_Object_ptr findObjectInFather( GEOM::GEOM_Object_ptr theFather, const QString& theName );
179 GEOM::GEOM_Object_ptr findObjectInFather( GEOM::GEOM_Object_ptr theFather, int theIndex );
180 // These methods are used to find published sub-object (sub-shape) in the parent object (main shape)
182 GEOM::GeomObjPtr getSelected( TopAbs_ShapeEnum type );
183 GEOM::GeomObjPtr getSelected( const QList<TopAbs_ShapeEnum>& types );
184 QList<GEOM::GeomObjPtr> getSelected( TopAbs_ShapeEnum type, int count, bool strict = true );
185 QList<GEOM::GeomObjPtr> getSelected( const QList<TopAbs_ShapeEnum>& types, int count, bool strict = true );
187 void hideSourceObjects( QList<GEOM::GeomObjPtr> theObjectList );
188 void SetIsPreview(const bool thePreview) {isPreview = thePreview;}
189 bool IsPreview() {return isPreview;}
191 GEOM_Displayer* getDisplayer();
192 SUIT_Desktop* getDesktop() const;
194 virtual void setIsApplyAndClose( const bool theFlag );
195 virtual bool isApplyAndClose() const;
197 virtual void setIsOptimizedBrowsing( const bool theFlag );
198 virtual bool isOptimizedBrowsing() const;
200 virtual void setIsWaitCursorEnabled( const bool theFlag ) {myIsWaitCursorEnabled = theFlag;}
201 virtual bool isWaitCursorEnabled() const {return myIsWaitCursorEnabled ;}
202 virtual void setIsDisableBrowsing( const bool theFlag ) { myIsDisableBrowsing = theFlag; }
203 virtual bool isDisableBrowsing() const { return myIsDisableBrowsing; }
204 virtual void setIsDisplayResult( const bool theFlag ) {myIsDisplayResult = theFlag; }
205 virtual bool isDisplayResult() const { return myIsDisplayResult; }
208 QString getEntry( GEOM::GEOM_Object_ptr ) const;
209 void clearShapeBuffer( GEOM::GEOM_Object_ptr );
212 typedef std::list<SALOME_Prs*> PrsList;
215 GEOM_Displayer* myDisplayer;
216 GEOM_Operation* myCommand;
217 GEOM::GEOM_IOperations_var myOperation;
218 SUIT_ViewWindow* myViewWindow;
221 SALOME_ListIO mySelected;
222 SUIT_Desktop* myDesktop;
223 bool myIsApplyAndClose;
224 bool myIsOptimizedBrowsing;
225 bool myIsWaitCursorEnabled;
226 bool myIsDisableBrowsing; //This flag enable/disable selection
227 //in the Object Browser newly created objects.
228 bool myIsDisplayResult; //This flag display/hide newly created objects.
231 #endif // GEOMBASE_HELPER_H