1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2004 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
24 // File : GEOMBase_Helper.h
25 // Author : Sergey ANIKIN
29 #ifndef GEOMBASE_HELPER_H
30 #define GEOMBASE_HELPER_H
32 #include "GEOM_GEOMBase.hxx"
34 #include "GEOM_Displayer.h"
35 #include "SALOME_ListIO.hxx"
36 #include <SALOMEconfig.h>
37 #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();
66 static GEOM::GEOM_Gen_ptr getGeomEngine();
68 void display ( const ObjectList&, const bool = true );
69 void display ( GEOM::GEOM_Object_ptr, const bool = true );
70 void erase ( const ObjectList&, const bool = true );
71 void erase ( GEOM::GEOM_Object_ptr, const bool = true );
72 void redisplay ( const ObjectList&, const bool = true, const bool = true );
73 void redisplay ( GEOM::GEOM_Object_ptr, const bool = true, const bool = true );
75 virtual void displayPreview ( const bool activate = false,
76 const bool update = true,
77 const bool toRemoveFromEngine = true,
78 const double lineWidth = -1,
79 const int displayMode = -1,
80 const int color = -1 );
81 // This is the easiest way to show preview. It is based on execute() method.
82 // It removes temporary GEOM::GEOM_Objects automatically.
84 virtual void displayPreview ( GEOM::GEOM_Object_ptr obj,
85 const bool append = false,
86 const bool activate = false,
87 const bool update = true,
88 const double lineWidth = -1,
89 const int displayMode = -1,
90 const int color = -1 );
91 void displayPreview ( const SALOME_Prs* prs,
92 const bool append = false,
94 void erasePreview ( const bool = true );
96 void localSelection( const ObjectList&, const int );
97 void localSelection( GEOM::GEOM_Object_ptr, const int );
98 void activate( const int );
99 void globalSelection( const int = GEOM_ALLOBJECTS, const bool = false );
100 void globalSelection( const TColStd_MapOfInteger&, const bool = false );
101 void updateViewer ();
103 void prepareSelection( const ObjectList&, const int );
104 void prepareSelection( GEOM::GEOM_Object_ptr, const int );
106 void addInStudy ( GEOM::GEOM_Object_ptr, const char* theName );
109 bool abortCommand ();
110 bool commitCommand ( const char* = 0 );
111 bool hasCommand () const;
113 void updateObjBrowser() const;
114 int getStudyId () const;
115 SalomeApp_Study* getStudy () const;
116 bool checkViewWindow ();
118 bool onAccept( const bool publish = true, const bool useTransaction = true );
119 // This method should be called from "OK" button handler.
120 // <publish> == true means that objects returned by execute()
121 // should be published in a study.
124 // Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
125 void showError( const QString& msg );
126 // Shows a error message followed by <msg>
128 GEOM::GEOM_IOperations_ptr getOperation();
129 // If <myOperation> is nil --> calls createOperation() and put the result
130 // into <myOperation> and returns it;
131 // otherwise, simply returns <myOperation>
133 inline void setPrefix( const QString& prefix ) { myPrefix = prefix; }
134 QString getPrefix( GEOM::GEOM_Object_ptr = GEOM::GEOM_Object::_nil() ) const;
136 const SALOME_ListIO& selectedIO();
137 // Function returns a list of SALOME_InteractiveObject's from
138 // selection manager in GUI
141 // Function returns the number of selected objects
143 Handle(SALOME_InteractiveObject) firstIObject() ;
144 // Function returns the first selected object in the list
145 // of selected objects
147 Handle(SALOME_InteractiveObject) lastIObject() ;
148 // Function returns the last selected object in the list
149 // of selected objects
151 bool selectObjects( ObjectList& objects );
152 // Selects list of objects
154 ////////////////////////////////////////////////////////////////////////////
155 // Virtual methods, to be redefined in dialog classes
156 ////////////////////////////////////////////////////////////////////////////
158 virtual GEOM::GEOM_IOperations_ptr createOperation();
159 // This method should be redefined in dialog boxes so as to return
160 // proper GEOM_IOperation interface.
161 // Returns nil reference by default
163 virtual bool isValid( QString& msg );
164 // Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
166 virtual bool execute( ObjectList& objects );
167 // This method is called by onAccept().
168 // It should perform the required operation and put all new or modified objects into
169 // <objects> argument.Should return <false> if some error occurs during its execution.
171 virtual GEOM::GEOM_Object_ptr getFather( GEOM::GEOM_Object_ptr theObj );
172 // This method is called by addInStudy(). It should return a father object
173 // for <theObj> or a nil reference if <theObj> should be published
174 // as a top-level object.
176 virtual const char* getNewObjectName() const;
178 void SetIsPreview(const bool thePreview) {isPreview = thePreview;}
179 bool IsPreview() {return isPreview;}
181 GEOM_Displayer* getDisplayer();
182 SUIT_Desktop* getDesktop() const;
185 char* getEntry ( GEOM::GEOM_Object_ptr ) const;
186 void clearShapeBuffer( GEOM::GEOM_Object_ptr );
189 typedef std::list<SALOME_Prs*> PrsList;
192 GEOM_Displayer* myDisplayer;
193 GEOM_Operation* myCommand;
194 GEOM::GEOM_IOperations_var myOperation;
195 SUIT_ViewWindow* myViewWindow;
198 SALOME_ListIO mySelected;
199 SUIT_Desktop* myDesktop;