1 // Copyright (C) 2007-2010 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
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"
32 #include <GEOM_Displayer.h>
33 #include <SALOME_ListIO.hxx>
34 #include <SALOMEconfig.h>
35 #include CORBA_CLIENT_HEADER(GEOM_Gen)
42 typedef std::list<GEOM::GEOM_Object_ptr> ObjectList;
44 class SalomeApp_Study;
46 class SUIT_ViewWindow;
49 class TColStd_MapOfInteger;
51 //================================================================
52 // Class : GEOMBase_Helper
53 // Description : Helper class for dialog box development, can be used as
54 // the second base class for dialog boxes. Contains convenient methods
55 // performing common operations (display/erase, selection activation,
56 // publication in a study, transaction management)
57 //================================================================
58 class GEOMBASE_EXPORT GEOMBase_Helper
61 GEOMBase_Helper( SUIT_Desktop* );
62 virtual ~GEOMBase_Helper();
65 static GEOM::GEOM_Gen_ptr getGeomEngine();
67 void display ( const ObjectList&, const bool = true );
68 void display ( GEOM::GEOM_Object_ptr, const bool = true );
69 void erase ( const ObjectList&, const bool = true );
70 void erase ( GEOM::GEOM_Object_ptr, const bool = true );
71 void redisplay ( const ObjectList&, const bool = true, const bool = true );
72 void redisplay ( GEOM::GEOM_Object_ptr, const bool = true, const bool = true );
74 virtual void displayPreview ( const bool activate = false,
75 const bool update = true,
76 const bool toRemoveFromEngine = true,
77 const double lineWidth = -1,
78 const int displayMode = -1,
79 const int color = -1 );
80 // This is the easiest way to show preview. It is based on execute() method.
81 // It removes temporary GEOM::GEOM_Objects automatically.
83 virtual void displayPreview ( GEOM::GEOM_Object_ptr obj,
84 const bool append = false,
85 const bool activate = false,
86 const bool update = true,
87 const double lineWidth = -1,
88 const int displayMode = -1,
89 const int color = -1 );
90 void displayPreview ( const SALOME_Prs* prs,
91 const bool append = false,
93 void erasePreview ( const bool = true );
95 void localSelection( const ObjectList&, const int );
96 void localSelection( GEOM::GEOM_Object_ptr, const int );
97 void activate( const int );
98 void globalSelection( const int = GEOM_ALLOBJECTS, const bool = false );
99 void globalSelection( const TColStd_MapOfInteger&, const bool = false );
100 void globalSelection( const TColStd_MapOfInteger&, const QList<int>& ,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 bool selectObjects( ObjectList& objects );
137 // Selects list of objects
139 ////////////////////////////////////////////////////////////////////////////
140 // Virtual methods, to be redefined in dialog classes
141 ////////////////////////////////////////////////////////////////////////////
143 virtual GEOM::GEOM_IOperations_ptr createOperation();
144 // This method should be redefined in dialog boxes so as to return
145 // proper GEOM_IOperation interface.
146 // Returns nil reference by default
148 virtual bool isValid( QString& msg );
149 // Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
151 virtual bool execute( ObjectList& objects );
152 // This method is called by onAccept().
153 // It should perform the required operation and put all new or modified objects into
154 // <objects> argument.Should return <false> if some error occurs during its execution.
156 virtual void restoreSubShapes( SALOMEDS::Study_ptr theStudy, SALOMEDS::SObject_ptr theSObject );
157 // This method is called by addInStudy().
159 virtual GEOM::GEOM_Object_ptr getFather( GEOM::GEOM_Object_ptr theObj );
160 // This method is called by addInStudy(). It should return a father object
161 // for <theObj> or a nil reference if <theObj> should be published
162 // as a top-level object.
164 virtual QString getNewObjectName() const;
165 virtual bool extractPrefix() const;
166 virtual void addSubshapesToStudy();
168 GEOM::GEOM_Object_ptr findObjectInFather( GEOM::GEOM_Object_ptr theFather, const QString& theName );
169 //This Metod to find SubObject in theFather Object by Name (theName)
171 void addSubshapesToFather( QMap<QString, GEOM::GEOM_Object_var>& theMap );
173 void SetIsPreview(const bool thePreview) {isPreview = thePreview;}
174 bool IsPreview() {return isPreview;}
176 GEOM_Displayer* getDisplayer();
177 SUIT_Desktop* getDesktop() const;
180 char* getEntry ( GEOM::GEOM_Object_ptr ) const;
181 void clearShapeBuffer( GEOM::GEOM_Object_ptr );
184 typedef std::list<SALOME_Prs*> PrsList;
187 GEOM_Displayer* myDisplayer;
188 GEOM_Operation* myCommand;
189 GEOM::GEOM_IOperations_var myOperation;
190 SUIT_ViewWindow* myViewWindow;
193 SALOME_ListIO mySelected;
194 SUIT_Desktop* myDesktop;
198 #endif // GEOMBASE_HELPER_H