Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/geom.git] / src / BooleanGUI / BooleanGUI.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : BooleanGUI.cxx
25 //  Author : Damien COQUERET
26 //  Module : GEOM
27 //  $Header: 
28
29 using namespace std;
30 #include "BooleanGUI.h"
31
32 #include "SALOMEGUI_QtCatchCorbaException.hxx"
33
34 #include "BooleanGUI_FuseDlg.h"    // Method FUSE
35 #include "BooleanGUI_CommonDlg.h"  // Method COMMON
36 #include "BooleanGUI_CutDlg.h"     // Method CUT
37 #include "BooleanGUI_SectionDlg.h" // Method SECTION
38
39 //=======================================================================
40 // function : BooleanGUI()
41 // purpose  : Constructor
42 //=======================================================================
43 BooleanGUI::BooleanGUI() :
44   QObject()
45 {
46   myGeomBase = new GEOMBase();
47   myGeomGUI = GEOMContext::GetGeomGUI();
48   myGeom = myGeomGUI->myComponentGeom;
49 }
50
51
52 //=======================================================================
53 // function : ~BooleanGUI()
54 // purpose  : Destructor
55 //=======================================================================
56 BooleanGUI::~BooleanGUI()
57 {
58 }
59
60
61 //=======================================================================
62 // function : OnGUIEvent()
63 // purpose  : 
64 //=======================================================================
65 bool BooleanGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
66 {
67   BooleanGUI* myBooleanGUI = new BooleanGUI();
68   myBooleanGUI->myGeomGUI->EmitSignalDeactivateDialog();
69   SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
70
71   switch (theCommandID)
72     {
73     case 5011: // FUSE
74       {
75         BooleanGUI_FuseDlg *aDlg = new BooleanGUI_FuseDlg(parent, "", myBooleanGUI, Sel);
76         break;
77       }
78     case 5012: // COMMON
79       {
80         BooleanGUI_CommonDlg *aDlg = new BooleanGUI_CommonDlg(parent, "", myBooleanGUI, Sel);
81         break;
82       }
83     case 5013: // CUT
84       {
85         BooleanGUI_CutDlg *aDlg = new BooleanGUI_CutDlg(parent, "", myBooleanGUI, Sel);
86         break;
87       }
88     case 5014: // SECTION
89       {
90         BooleanGUI_SectionDlg *aDlg = new BooleanGUI_SectionDlg(parent, "", myBooleanGUI, Sel);
91         break;
92       }
93     default:
94       {
95         parent->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
96         break;
97       }
98     }
99   return true;
100 }
101
102
103 //=======================================================================
104 // function : MakeBooleanAndDisplay()
105 // purpose  : 
106 //=======================================================================
107 void BooleanGUI::MakeBooleanAndDisplay(GEOM::GEOM_Shape_ptr Shape1, GEOM::GEOM_Shape_ptr Shape2, const short operation)
108 {
109   try {
110     GEOM::GEOM_Shape_ptr result = myGeom->MakeBoolean(Shape1, Shape2, operation);
111     if(result->_is_nil()) {
112       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_NULLSHAPE")); 
113       return;
114     }  
115
116     TopoDS_Shape S = myGeomGUI->GetShapeReader().GetShape(myGeom, result);
117     Standard_CString type;
118     myGeomBase->GetShapeTypeString(S,type);
119     result->NameType(type);
120
121     if (myGeomBase->Display(result))
122       QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_DONE"));
123   }
124   catch (const SALOME::SALOME_Exception& S_ex) {
125     QtCatchCorbaException(S_ex);
126   }
127   return;
128 }
129
130
131 //=====================================================================================
132 // EXPORTED METHODS
133 //=====================================================================================
134 extern "C"
135 {
136   bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
137   {return BooleanGUI::OnGUIEvent(theCommandID, parent);}
138 }