Back to index

salome-geom  6.5.0
GEOMBase_Helper.h
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // GEOM GEOMGUI : GUI for Geometry component
00024 // File   : GEOMBase_Helper.h
00025 // Author : Sergey ANIKIN, Open CASCADE S.A.S. (sergey.anikin@opencascade.com)
00026 //
00027 #ifndef GEOMBASE_HELPER_H
00028 #define GEOMBASE_HELPER_H
00029 
00030 #include "GEOM_GEOMBase.hxx"
00031 #include "GEOM_GenericObjPtr.h"
00032 
00033 #include <GEOM_Displayer.h>
00034 #include <SALOME_ListIO.hxx>
00035 #include <SALOMEconfig.h>
00036 #include CORBA_CLIENT_HEADER(GEOM_Gen)
00037 
00038 #include <QString>
00039 #include <QMap>
00040 
00041 #include <list>
00042 
00043 typedef std::list<GEOM::GEOM_Object_ptr> ObjectList;
00044 
00045 class SalomeApp_Study;
00046 class SUIT_Desktop;
00047 class SUIT_ViewWindow;
00048 class SALOME_Prs;
00049 class GEOM_Operation;
00050 class TColStd_MapOfInteger;
00051 
00052 //================================================================
00053 // Class       : GEOMBase_Helper
00054 // Description : Helper class for dialog box development, can be used as 
00055 //               the second base class for dialog boxes. Contains convenient methods
00056 //               performing common operations (display/erase, selection activation,
00057 //               publication in a study, transaction management)
00058 //================================================================
00059 class GEOMBASE_EXPORT GEOMBase_Helper
00060 {
00061 public:
00062   GEOMBase_Helper( SUIT_Desktop* );
00063   virtual ~GEOMBase_Helper();
00064 
00065 protected:
00066   static GEOM::GEOM_Gen_ptr getGeomEngine();
00067 
00068   void display         ( const ObjectList&, const bool = true );
00069   void display         ( GEOM::GEOM_Object_ptr, const bool = true );
00070   void erase           ( const ObjectList&, const bool = true );
00071   void erase           ( GEOM::GEOM_Object_ptr, const bool = true );
00072   void redisplay       ( const ObjectList&, const bool = true, const bool = true );
00073   void redisplay       ( GEOM::GEOM_Object_ptr, const bool = true, const bool = true );
00074 
00075   virtual void displayPreview ( const bool   display,
00076                                 const bool   activate = false, 
00077                                 const bool   update = true,
00078                                 const bool   toRemoveFromEngine = true,
00079                                 const double lineWidth = -1, 
00080                                 const int    displayMode = -1,
00081                                 const int    color  = -1 );
00082   // This is the easiest way to show preview. It is based on execute() method.
00083   // It removes temporary GEOM::GEOM_Objects automatically.
00084 
00085   virtual void displayPreview  ( GEOM::GEOM_Object_ptr obj, 
00086                                  const bool   append = false, 
00087                                  const bool   activate = false, 
00088                                  const bool   update = true,
00089                                  const double lineWidth = -1, 
00090                                  const int    displayMode = -1,
00091                                  const int    color  = -1 );
00092   void displayPreview  ( const SALOME_Prs* prs, 
00093                          const bool append = false, 
00094                          const bool = true );
00095   void erasePreview    ( const bool = true );
00096 
00097   void localSelection( const ObjectList&, const int );
00098   void localSelection( GEOM::GEOM_Object_ptr, const int );
00099   void activate( const int );
00100   void globalSelection( const int = GEOM_ALLOBJECTS, const bool = false  );
00101   void globalSelection( const TColStd_MapOfInteger&, const bool = false );
00102   void globalSelection( const TColStd_MapOfInteger&, const QList<int>& ,const bool = false );
00103   void updateViewer    ();
00104 
00105   void prepareSelection( const ObjectList&, const int );
00106   void prepareSelection( GEOM::GEOM_Object_ptr, const int );
00107 
00108   QString addInStudy   ( GEOM::GEOM_Object_ptr, const char* theName ); 
00109 
00110   bool openCommand     ();
00111   bool abortCommand    ();
00112   bool commitCommand   ( const char* = 0 );
00113   bool hasCommand      () const;
00114 
00115   void updateObjBrowser() const;
00116   int  getStudyId      () const;
00117   SalomeApp_Study* getStudy  () const;
00118   bool checkViewWindow ();
00119 
00120   bool onAccept( const bool publish = true, const bool useTransaction = true, bool erasePreviewFlag = true);
00121   // This method should be called from "OK" button handler.
00122   // <publish> == true means that objects returned by execute() 
00123   // should be published in a study.
00124 
00125   void showError();
00126   // Shows a message box with infromation about an error taken from getOperation()->GetErrorCode()
00127   void showError( const QString& msg );
00128   // Shows a error message followed by <msg>
00129 
00130   GEOM::GEOM_IOperations_ptr getOperation();
00131   // If <myOperation> is nil --> calls createOperation() and put the result
00132   // into <myOperation> and returns it;
00133   // otherwise, simply returns <myOperation>
00134 
00135   inline void setPrefix( const QString& prefix ) { myPrefix = prefix; }
00136   QString getPrefix( GEOM::GEOM_Object_ptr = GEOM::GEOM_Object::_nil() ) const;
00137   
00138   bool selectObjects( ObjectList& objects );
00139   // Selects list of objects 
00140 
00142   // Virtual methods, to be redefined in dialog classes
00144 
00145   virtual GEOM::GEOM_IOperations_ptr createOperation();
00146   // This method should be redefined in dialog boxes so as to return 
00147   // proper GEOM_IOperation interface.
00148   // Returns nil reference by default
00149 
00150   virtual bool isValid( QString& msg );
00151   // Called by onAccept(). Redefine this method to check validity of user input in dialog boxes.
00152 
00153   virtual bool execute( ObjectList& objects );
00154   // This method is called by onAccept(). 
00155   // It should perform the required operation and put all new or modified objects into 
00156   // <objects> argument.Should return <false> if some error occurs during its execution. 
00157 
00158   virtual void restoreSubShapes( SALOMEDS::Study_ptr theStudy, SALOMEDS::SObject_ptr theSObject );
00159   // This method is called by addInStudy().
00160 
00161   virtual GEOM::GEOM_Object_ptr getFather( GEOM::GEOM_Object_ptr theObj );
00162   // This method is called by addInStudy(). It should return a father object
00163   // for <theObj> or a nil reference if <theObj> should be published
00164   // as a top-level object.
00165 
00166   virtual QString getNewObjectName() const; 
00167   virtual bool extractPrefix() const;
00168   virtual void addSubshapesToStudy();
00169 
00170   GEOM::GEOM_Object_ptr findObjectInFather( GEOM::GEOM_Object_ptr theFather, const QString& theName );
00171   GEOM::GEOM_Object_ptr findObjectInFather( GEOM::GEOM_Object_ptr theFather, int theIndex );
00172   // These methods are used to find published sub-object (sub-shape) in the parent object (main shape)
00173 
00174   GEOM::GeomObjPtr        getSelected( TopAbs_ShapeEnum type );
00175   GEOM::GeomObjPtr        getSelected( const QList<TopAbs_ShapeEnum>& types );
00176   QList<GEOM::GeomObjPtr> getSelected( TopAbs_ShapeEnum type, int count, bool strict = true );
00177   QList<GEOM::GeomObjPtr> getSelected( const QList<TopAbs_ShapeEnum>& types, int count, bool strict = true );
00178 
00179   void SetIsPreview(const bool thePreview) {isPreview = thePreview;}
00180   bool IsPreview() {return isPreview;}
00181 
00182   GEOM_Displayer*             getDisplayer();
00183   SUIT_Desktop*               getDesktop() const;
00184 
00185   virtual void                setIsApplyAndClose( const bool theFlag );
00186   virtual bool                isApplyAndClose() const;
00187 
00188   virtual void                setIsOptimizedBrowsing( const bool theFlag );
00189   virtual bool                isOptimizedBrowsing() const;
00190   
00191   virtual void                setIsWaitCursorEnabled( const bool theFlag ) {myIsWaitCursorEnabled = theFlag;}
00192   virtual bool                isWaitCursorEnabled() const {return myIsWaitCursorEnabled ;}
00193   virtual void                setIsDisableBrowsing( const bool theFlag ) { myIsDisableBrowsing = theFlag; }
00194   virtual bool                isDisableBrowsing() const { return myIsDisableBrowsing; }
00195   
00196 
00197 private:
00198   QString                     getEntry( GEOM::GEOM_Object_ptr ) const;
00199   void                        clearShapeBuffer( GEOM::GEOM_Object_ptr );
00200 
00201 private:
00202   typedef std::list<SALOME_Prs*> PrsList;
00203 
00204   PrsList                     myPreview;
00205   GEOM_Displayer*             myDisplayer;
00206   GEOM_Operation*             myCommand;
00207   GEOM::GEOM_IOperations_var  myOperation;
00208   SUIT_ViewWindow*            myViewWindow;
00209   QString                     myPrefix;
00210   bool                        isPreview;
00211   SALOME_ListIO               mySelected;
00212   SUIT_Desktop*               myDesktop;
00213   bool                        myIsApplyAndClose;
00214   bool                        myIsOptimizedBrowsing;
00215   bool                        myIsWaitCursorEnabled;
00216   bool                        myIsDisableBrowsing;  //This flag enable/disable selection 
00217                                                     //in the Object Browser newly created objects.
00218 
00219 };
00220 
00221 #endif // GEOMBASE_HELPER_H