1 // Copyright (C) 2007-2008 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.
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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : GEOMBase_Helper.h
24 // Author : Sergey ANIKIN
28 #ifndef GEOMBASE_HELPER_H
29 #define GEOMBASE_HELPER_H
31 #include "GEOM_GEOMBase.hxx"
33 #include "GEOM_Displayer.h"
34 #include "SALOME_Prs.h"
35 #include "SALOME_ListIO.hxx"
36 #include <SALOMEconfig.h>
37 #include CORBA_CLIENT_HEADER(GEOM_Gen)
44 typedef std::list<GEOM::GEOM_Object_ptr> ObjectList;
46 class SalomeApp_Study;
48 class SUIT_ViewWindow;
51 class TColStd_MapOfInteger;
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 //================================================================
60 class GEOMBASE_EXPORT GEOMBase_Helper
63 GEOMBase_Helper( SUIT_Desktop* );
64 virtual ~GEOMBase_Helper();
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 activate = false,
77 const bool update = true,
78 const bool toRemoveFromEngine = true,
79 const double lineWidth = -1,
80 const int displayMode = -1,
81 const int color = -1 );
82 // This is the easiest way to show preview. It is based on execute() method.
83 // It removes temporary GEOM::GEOM_Objects automatically.
85 virtual void displayPreview ( GEOM::GEOM_Object_ptr obj,
86 const bool append = false,
87 const bool activate = false,
88 const bool update = true,
89 const double lineWidth = -1,
90 const int displayMode = -1,
91 const int color = -1 );
92 void displayPreview ( const SALOME_Prs* prs,
93 const bool append = false,
95 void erasePreview ( const bool = true );
97 void localSelection( const ObjectList&, const int );
98 void localSelection( GEOM::GEOM_Object_ptr, const int );
99 void activate( const int );
100 void globalSelection( const int = GEOM_ALLOBJECTS, const bool = false );
101 void globalSelection( const TColStd_MapOfInteger&, const bool = false );
102 void globalSelection( const TColStd_MapOfInteger&, const QValueList<int>& ,const bool = false );
103 void updateViewer ();
105 void prepareSelection( const ObjectList&, const int );
106 void prepareSelection( GEOM::GEOM_Object_ptr, const int );
108 void addInStudy ( GEOM::GEOM_Object_ptr, const char* theName );
111 bool abortCommand ();
112 bool commitCommand ( const char* = 0 );
113 bool hasCommand () const;
115 void updateObjBrowser() const;
116 int getStudyId () const;
117 SalomeApp_Study* getStudy () const;
118 bool checkViewWindow ();
120 bool onAccept( const bool publish = true, const bool useTransaction = true );
121 // This method should be called from "OK" button handler.
122 // <publish> == true means that objects returned by execute()
123 // should be published in a study.
126 // Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
127 void showError( const QString& msg );
128 // Shows a error message followed by <msg>
130 GEOM::GEOM_IOperations_ptr getOperation();
131 // If <myOperation> is nil --> calls createOperation() and put the result
132 // into <myOperation> and returns it;
133 // otherwise, simply returns <myOperation>
135 inline void setPrefix( const QString& prefix ) { myPrefix = prefix; }
136 QString getPrefix( GEOM::GEOM_Object_ptr = GEOM::GEOM_Object::_nil() ) const;
138 const SALOME_ListIO& selectedIO();
139 // Function returns a list of SALOME_InteractiveObject's from
140 // selection manager in GUI
143 // Function returns the number of selected objects
145 Handle(SALOME_InteractiveObject) firstIObject() ;
146 // Function returns the first selected object in the list
147 // of selected objects
149 Handle(SALOME_InteractiveObject) lastIObject() ;
150 // Function returns the last selected object in the list
151 // of selected objects
153 bool selectObjects( ObjectList& objects );
154 // Selects list of objects
156 ////////////////////////////////////////////////////////////////////////////
157 // Virtual methods, to be redefined in dialog classes
158 ////////////////////////////////////////////////////////////////////////////
160 virtual GEOM::GEOM_IOperations_ptr createOperation();
161 // This method should be redefined in dialog boxes so as to return
162 // proper GEOM_IOperation interface.
163 // Returns nil reference by default
165 virtual bool isValid( QString& msg );
166 // Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
168 virtual bool execute( ObjectList& objects );
169 // This method is called by onAccept().
170 // It should perform the required operation and put all new or modified objects into
171 // <objects> argument.Should return <false> if some error occurs during its execution.
173 virtual void restoreSubShapes (SALOMEDS::Study_ptr theStudy, SALOMEDS::SObject_ptr theSObject);
174 // This method is called by addInStudy().
176 virtual GEOM::GEOM_Object_ptr getFather( GEOM::GEOM_Object_ptr theObj );
177 // This method is called by addInStudy(). It should return a father object
178 // for <theObj> or a nil reference if <theObj> should be published
179 // as a top-level object.
181 virtual const char* getNewObjectName() const;
182 virtual void addSubshapesToStudy();
184 GEOM::GEOM_Object_ptr findObjectInFather( GEOM::GEOM_Object_ptr theFather, const char* theName );
185 //This Metod to find SubObject in theFather Object by Name (theName)
187 void addSubshapesToFather( QMap<QString, GEOM::GEOM_Object_var>& theMap );
189 void SetIsPreview(const bool thePreview) {isPreview = thePreview;}
190 bool IsPreview() {return isPreview;}
192 GEOM_Displayer* getDisplayer();
193 SUIT_Desktop* getDesktop() const;
196 char* getEntry ( GEOM::GEOM_Object_ptr ) const;
197 void clearShapeBuffer( GEOM::GEOM_Object_ptr );
200 typedef std::list<SALOME_Prs*> PrsList;
203 GEOM_Displayer* myDisplayer;
204 GEOM_Operation* myCommand;
205 GEOM::GEOM_IOperations_var myOperation;
206 SUIT_ViewWindow* myViewWindow;
209 SALOME_ListIO mySelected;
210 SUIT_Desktop* myDesktop;