Salome HOME
Preparation of intermediate revision
[modules/geom.git] / src / RepairGUI / RepairGUI.cxx
index 0c456bdd721f84c4254d6a6c956b9d1e078c7c4e..ff1045d495e716d9c8303c440db5f4444b26390b 100644 (file)
@@ -1,58 +1,58 @@
-//  GEOM GEOMGUI : GUI for Geometry component
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  License along with this library; if not, write to the Free Software 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
 //
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+// GEOM GEOMGUI : GUI for Geometry component
+// File   : RepairGUI.cxx
+// Author : Damien COQUERET, Open CASCADE S.A.S.
 //
-//  File   : RepairGUI.cxx
-//  Author : Damien COQUERET
-//  Module : GEOM
-//  $Header: 
-
-using namespace std;
 #include "RepairGUI.h"
 
-#include "QAD_RightFrame.h"
-#include "OCCViewer_Viewer3d.h"
-#include "SALOMEGUI_QtCatchCorbaException.hxx"
+#include <GeometryGUI.h>
+
+#include <SUIT_Desktop.h>
+#include <SUIT_Session.h>
+#include <SalomeApp_Application.h>
 
 #include "RepairGUI_SewingDlg.h"        // Method SEWING
-#include "RepairGUI_OrientationDlg.h"   // Method ORIENTATION
 #include "RepairGUI_SuppressFacesDlg.h" // Method SUPPRESS FACES
-#include "RepairGUI_SuppressHoleDlg.h"  // Method SUPPRESS HOLE
+#include "RepairGUI_RemoveHolesDlg.h"   // Method SUPPRESS HOLE
+#include "RepairGUI_ShapeProcessDlg.h"  // Method PROCESS SHAPE
+#include "RepairGUI_CloseContourDlg.h"  // Method CLOSE CONTOUR
+#include "RepairGUI_RemoveIntWiresDlg.h"// Method REMOVE INTERNAL WIRES
+#include "RepairGUI_DivideEdgeDlg.h"    // Method DEVIDE EDGE
+#include "RepairGUI_FreeBoundDlg.h"     // Method FREE BOUNDARIES
+#include "RepairGUI_FreeFacesDlg.h"     // Method FREE FACES
+#include "RepairGUI_GlueDlg.h"          // Method GLUE FACES
+#include "RepairGUI_ChangeOrientationDlg.h" // Method CHANGE ORIENTATION
+#include "RepairGUI_RemoveExtraEdgesDlg.h" // Method REMOVE EXTRA EDGES
 
 //=======================================================================
 // function : RepairGUI()
 // purpose  : Constructor
 //=======================================================================
-RepairGUI::RepairGUI() :
-  QObject()
+RepairGUI::RepairGUI( GeometryGUI* parent )
+  : GEOMGUI( parent )
 {
-  myGeomBase = new GEOMBase();
-  myGeomGUI = GEOMContext::GetGeomGUI();
-//   Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer", "GEOM");
-//   myGeom = GEOM::GEOM_Gen::_narrow(comp);
-  myGeom = myGeomGUI->myComponentGeom;
 }
 
-
 //=======================================================================
 // function : ~RepairGUI()
 // purpose  : Destructor
@@ -66,266 +66,35 @@ RepairGUI::~RepairGUI()
 // function : OnGUIEvent()
 // purpose  : 
 //=======================================================================
-bool RepairGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
+bool RepairGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
 {
-  RepairGUI* myRepairGUI = new RepairGUI();
-  myRepairGUI->myGeomGUI->EmitSignalDeactivateDialog();
-  SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
-
-  switch (theCommandID)
-    {
-    case 601: // SEWING
-      {
-       RepairGUI_SewingDlg *aDlg = new RepairGUI_SewingDlg(parent, "", myRepairGUI, Sel);
-       break;
-      }
-    case 602: // ORIENTATION
-      {
-       RepairGUI_OrientationDlg *aDlg = new RepairGUI_OrientationDlg(parent, "", myRepairGUI, Sel);
-       break;
-      }
-    case 603: // SUPPRESS FACES : use ic
-      {
-       Handle(AIS_InteractiveContext) ic;
-       if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
-         OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
-         ic = v3d->getAISContext();
-       }
-       RepairGUI_SuppressFacesDlg *aDlg = new RepairGUI_SuppressFacesDlg(parent, "", myRepairGUI, Sel, ic);
-       break;
-      }
-    case 604: // SUPPRESS HOLES : use ic
-      {
-       Handle(AIS_InteractiveContext) ic;
-       if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
-         OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
-         ic = v3d->getAISContext();
-       }
-       RepairGUI_SuppressHoleDlg *aDlg = new RepairGUI_SuppressHoleDlg(parent, "", myRepairGUI, Sel, ic);
-       break;
-      }
+  SalomeApp_Application* app = getGeometryGUI()->getApp();
+  if ( !app ) return false;
+
+  getGeometryGUI()->EmitSignalDeactivateDialog();
+
+  QDialog* aDlg = NULL;
+  switch ( theCommandID ) {
+    case 601: aDlg = new RepairGUI_SewingDlg            ( getGeometryGUI(), parent ); break;
+    case 602: aDlg = new RepairGUI_GlueDlg              ( getGeometryGUI(), parent ); break;
+    case 603: aDlg = new RepairGUI_SuppressFacesDlg     ( getGeometryGUI(), parent ); break;
+    case 604: aDlg = new RepairGUI_RemoveHolesDlg       ( getGeometryGUI(), parent ); break;
+    case 605: aDlg = new RepairGUI_ShapeProcessDlg      ( getGeometryGUI(), parent ); break;
+    case 606: aDlg = new RepairGUI_CloseContourDlg      ( getGeometryGUI(), parent ); break;
+    case 607: aDlg = new RepairGUI_RemoveIntWiresDlg    ( getGeometryGUI(), parent ); break;
+    case 608: aDlg = new RepairGUI_DivideEdgeDlg        ( getGeometryGUI(), parent ); break;
+    case 609: aDlg = new RepairGUI_FreeBoundDlg         ( getGeometryGUI(), parent ); break;
+    case 610: aDlg = new RepairGUI_FreeFacesDlg         ( getGeometryGUI(), parent ); break;
+    case 611: aDlg = new RepairGUI_ChangeOrientationDlg ( getGeometryGUI(), parent ); break;
+    case 612: aDlg = new RepairGUI_RemoveExtraEdgesDlg  ( getGeometryGUI(), parent ); break;  
     default:
-      {
-       parent->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
-       break;
-      }
-    }
-  return true;
-}
-
-
-//=====================================================================================
-// function : MakeSewingAndDisplay()
-// purpose  :
-//=====================================================================================
-void RepairGUI::MakeSewingAndDisplay(GEOM::GEOM_Gen::ListOfIOR& listShapesIOR,
-                                    const Standard_Real precision)
-{
-  try {
-    GEOM::GEOM_Shape_var result = myGeom->MakeSewing(listShapesIOR, precision);
-    if(result->_is_nil()) {
-      QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_NULLSHAPE"));
-      return;
-    }
-
-    TopoDS_Shape S = myGeomGUI->GetShapeReader().GetShape(myGeom, result);
-    Standard_CString type;
-    myGeomBase->GetShapeTypeString(S,type);
-    result->NameType(type);
-
-    if(myGeomBase->Display(result))
-      QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
-    return;
-  }
-  catch(const SALOME::SALOME_Exception& S_ex) {
-    QtCatchCorbaException(S_ex);
-  }
-  return;
-}
-
-
-//=====================================================================================
-// function : MakeOrientationChangeAndDisplay()
-// purpose  :
-//=====================================================================================
-void RepairGUI::MakeOrientationChangeAndDisplay(GEOM::GEOM_Shape_ptr Shape)
-{
-  try {
-    GEOM::GEOM_Shape_var result = myGeom->OrientationChange(Shape);
-    if(result->_is_nil()) {
-      QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_NULLSHAPE"));
-      return;
-    }
-    result->NameType(Shape->NameType());
-    if(myGeomBase->Display(result))
-      QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE")); 
-    return;
-  }
-  catch(const SALOME::SALOME_Exception& S_ex) {
-    QtCatchCorbaException(S_ex);
-  }
-  return;
-}
-
-
-//=====================================================================================
-// function : OnSuppressHole() 
-// purpose  : To suppress an hole on a shape 'ShapeTopo'.
-//          : 'ListOfIdEndFace' may be an empty list.
-//          : This means that hole do not traverse ShapeTopo.
-//          : Warning : the hole to be suppressed must be defined by one or two single closed wires !
-//=====================================================================================
-bool RepairGUI::OnSuppressHole(const char* ShapeTopoIOR,
-                              const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfIdFace,
-                              const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfIdWire,
-                              const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfIdEndFace)
-{
-  /* Test the type of viewer */
-  if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC )
-    return false;
-  
-  try {
-    GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(ShapeTopoIOR);    
-    GEOM::GEOM_Shape_var aResult = myGeom->SuppressHole(aShape, ListOfIdFace, ListOfIdWire, ListOfIdEndFace);
-  
-    TopoDS_Shape S = myGeomGUI->GetShapeReader().GetShape(myGeom, aResult);
-    Standard_CString type;
-    myGeomBase->GetShapeTypeString(S,type);
-    aResult->NameType(type);
-
-    if(myGeomBase->Display(aResult))
-      QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
+      app->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) );
+      break;
   }
-  catch(const SALOME::SALOME_Exception& S_ex) {
-    QtCatchCorbaException(S_ex);
-  }
-  return true;
-}
 
+  if ( aDlg )
+    aDlg->show();
 
-//=====================================================================================
-// function : OnSuppressHolesInFaceOrShell() 
-// purpose  : To suppress one or more holes on a face
-//          : 'ListOfIdWires' contains indices or wires/holes.
-//=====================================================================================
-bool RepairGUI::OnSuppressHolesInFaceOrShell(const char* ShapeTopoIOR,
-                                            const GEOM::GEOM_Shape::ListOfSubShapeID& ListOfIdWires)
-{
-  /* Test the type of viewer */
-  if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
-    return false;
-  
-  try {
-    GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(ShapeTopoIOR);    
-    GEOM::GEOM_Shape_var aResult = myGeom->SuppressHolesInFaceOrShell(aShape, ListOfIdWires);
-    
-    TopoDS_Shape S = myGeomGUI->GetShapeReader().GetShape(myGeom, aResult);
-    Standard_CString type;
-    myGeomBase->GetShapeTypeString(S,type);
-    aResult->NameType(type);
-    
-    if(myGeomBase->Display(aResult))
-      QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
-  }
-  catch(const SALOME::SALOME_Exception& S_ex) {
-    QtCatchCorbaException(S_ex);
-  }
-  return true;
-}
-
-
-//=====================================================================================
-// function : OnSuppressFaces() 
-// purpose  : To suppress faces from a shape
-//          : The result is one or more shells/faces as main shapes !
-//=====================================================================================
-bool RepairGUI::OnSuppressFaces(const TopoDS_Shape& ShapeTopo, const char* ShapeTopoIOR,
-                               const Standard_Integer& aLocalContextId, bool& myUseLocalContext)
-{
-  /* Test the type of viewer */
-  if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
-    return false;
-  
-  SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
-  SALOMEDS::SObject_var theObj = aStudy->FindObjectIOR(ShapeTopoIOR);
-  if(theObj->_is_nil()) {
-    QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SHAPE_IN_STUDY"));
-    return false;
-  }
-  
-  OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
-  Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
-  
-  if(myUseLocalContext == false) {
-    /* local context is from DialogBox */
-    MESSAGE("Error : No local context opened for suppress faces method" << endl);
-    return false;
-  }
-  
-  GEOM::GEOM_Shape::ListOfSubShapeID_var ListOfID = new GEOM::GEOM_Shape::ListOfSubShapeID;
-  ic->InitSelected();
-  int nbSelected = ic->NbSelected();
-  ListOfID->length(nbSelected);
-
-  /* Create a list of indices of faces to be suppressed */
-  int i = 0;
-  const int SubShapeType = 4; /* GEOM::FACE type */
-  ic->InitSelected();          /* to repositioning at beginning */
-  while(ic->MoreSelected()) {
-    int index = myGeomBase->GetIndex(ic->SelectedShape(), ShapeTopo, SubShapeType);
-    ListOfID[i] = index;
-    i++;
-    ic->NextSelected();
-  }
-  
-  /* Close local context opened in DialogBox */
-  ic->CloseLocalContext(aLocalContextId);
-  myUseLocalContext = false;
-  
-  /* Here is the main shape */
-  GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(ShapeTopoIOR);  
-  GEOM::GEOM_Gen::ListOfGeomShapes_var listGeomShapes = new GEOM::GEOM_Gen::ListOfGeomShapes;
-  
-  /* Call geom method that return a list of shells/faces as result of suppress */
-  try {
-    listGeomShapes = myGeom->SuppressFaces(aShape, ListOfID);
-  }
-  catch(const SALOME::SALOME_Exception& S_ex) {
-    QtCatchCorbaException(S_ex);
-  }
-  
-  /* Test list of shells/faces */
-  if(listGeomShapes->length() < 1) {
-    return false;
-  }
-
-  /* Loop on each object created */
-  for(int i=0; i<listGeomShapes->length(); i++) {
-    GEOM::GEOM_Shape_var aShellOrFace = listGeomShapes[i];
-    TopoDS_Shape S = myGeomGUI->GetShapeReader().GetShape(myGeom, aShellOrFace);
-    
-    if(S.IsNull())
-      return false;
-    
-    char* nameG = (char *)malloc(20);
-    Standard_CString Type;
-    if(myGeomBase->GetShapeTypeString(S, Type)) {
-      aShellOrFace->NameType(Type);
-      sprintf (nameG, "%s_%d", Type, myGeomGUI->GetNbGeom()++);
-    }
-    else {
-      aShellOrFace->NameType(tr("GEOM_SHAPE"));
-      sprintf (nameG, "%s_%d", tr("GEOM_SHAPE").latin1(), myGeomGUI->GetNbGeom()++);
-    }
-    
-    /* Display with name */
-    if(!myGeomBase->Display(aShellOrFace, nameG)) {
-      QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_ABORT"));
-      return false;
-    }
-  }
-  
-  QAD_Application::getDesktop()->putInfo (tr("GEOM_PRP_READY"));
   return true;
 }
 
@@ -335,6 +104,11 @@ bool RepairGUI::OnSuppressFaces(const TopoDS_Shape& ShapeTopo, const char* Shape
 //=====================================================================================
 extern "C"
 {
-  bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
-  {return RepairGUI::OnGUIEvent(theCommandID, parent);}
+#ifdef WNT
+  __declspec( dllexport )
+#endif
+  GEOMGUI* GetLibGUI( GeometryGUI* parent )
+  {
+    return new RepairGUI( parent );
+  }
 }