1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : PrimitiveGUI_SphereDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "PrimitiveGUI_SphereDlg.h"
32 #include <BRepPrimAPI_MakeSphere.hxx>
33 #include "QAD_Config.h"
35 //=================================================================================
36 // class : PrimitiveGUI_SphereDlg()
37 // purpose : Constructs a PrimitiveGUI_SphereDlg which is a child of 'parent', with the
38 // name 'name' and widget flags set to 'f'.
39 // The dialog will by default be modeless, unless you set 'modal' to
40 // TRUE to construct a modal dialog.
41 //=================================================================================
42 PrimitiveGUI_SphereDlg::PrimitiveGUI_SphereDlg(QWidget* parent, const char* name, PrimitiveGUI* thePrimitiveGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
43 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
45 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_SPHERE_P")));
46 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_SPHERE_DXYZ")));
47 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
49 setCaption(tr("GEOM_SPHERE_TITLE"));
51 /***************************************************************/
52 GroupConstructors->setTitle(tr("GEOM_SPHERE"));
53 RadioButton1->setPixmap(image0);
54 RadioButton2->setPixmap(image1);
55 RadioButton3->close(TRUE);
57 GroupPoints = new DlgRef_1Sel1Spin(this, "GroupPoints");
58 GroupPoints->GroupBox1->setTitle(tr("GEOM_SPHERE_CR"));
59 GroupPoints->TextLabel1->setText(tr("GEOM_CENTER"));
60 GroupPoints->TextLabel2->setText(tr("GEOM_RADIUS"));
61 GroupPoints->PushButton1->setPixmap(image2);
63 GroupDimensions = new DlgRef_1Spin(this, "GroupDimensions");
64 GroupDimensions->GroupBox1->setTitle(tr("GEOM_SPHERE_RO"));
65 GroupDimensions->TextLabel1->setText(tr("GEOM_RADIUS"));
67 Layout1->addWidget(GroupPoints, 1, 0);
68 Layout1->addWidget(GroupDimensions, 1, 0);
69 /***************************************************************/
72 myPrimitiveGUI = thePrimitiveGUI;
77 //=================================================================================
78 // function : ~PrimitiveGUI_SphereDlg()
79 // purpose : Destroys the object and frees any allocated resources
80 //=================================================================================
81 PrimitiveGUI_SphereDlg::~PrimitiveGUI_SphereDlg()
83 /* no need to delete child widgets, Qt does it all for us */
87 //=================================================================================
90 //=================================================================================
91 void PrimitiveGUI_SphereDlg::Init()
95 myEditCurrentArgument = GroupPoints->LineEdit1;
97 myPoint1.SetCoord(0.0, 0.0, 0.0);
101 /* Vertices Filter for all arguments */
102 myVertexFilter = new GEOM_ShapeTypeFilter(TopAbs_VERTEX, myGeom);
103 mySelection->AddFilter(myVertexFilter);
105 /* Get setting of step value from file configuration */
106 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
107 step = St.toDouble();
109 /* min, max, step and decimals for spin boxes */
110 GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
111 GroupDimensions->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
112 GroupPoints->SpinBox_DX->SetValue(myRadius);
113 GroupDimensions->SpinBox_DX->SetValue(myRadius);
115 /* signals and slots connections */
116 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
117 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
118 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
120 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
121 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
123 connect(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
124 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
126 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
127 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX, SLOT(SetStep(double)));
129 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
131 /* displays Dialog */
132 GroupDimensions->hide();
140 //=================================================================================
141 // function : ConstructorsClicked()
142 // purpose : Radio button management
143 //=================================================================================
144 void PrimitiveGUI_SphereDlg::ConstructorsClicked(int constructorId)
146 myConstructorId = constructorId;
147 mySelection->ClearFilters();
148 myGeomBase->EraseSimulationShape();
149 disconnect(mySelection, 0, this, 0);
152 switch (constructorId)
156 GroupDimensions->hide();
160 myEditCurrentArgument = GroupPoints->LineEdit1;
161 GroupPoints->LineEdit1->setText("");
163 GroupPoints->SpinBox_DX->SetValue(myRadius);
166 /* filter for next selections */
167 mySelection->AddFilter(myVertexFilter);
168 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
175 GroupDimensions->show();
177 GroupDimensions->SpinBox_DX->SetValue(myRadius);
178 myPoint1.SetCoord(0.0, 0.0, 0.0); /* at origin */
181 mySimulationTopoDs = BRepPrimAPI_MakeSphere(myPoint1, myRadius).Shape();
182 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
190 //=================================================================================
191 // function : ClickOnOk()
193 //=================================================================================
194 void PrimitiveGUI_SphereDlg::ClickOnOk()
196 this->ClickOnApply();
202 //=================================================================================
203 // function : ClickOnApply()
205 //=================================================================================
206 void PrimitiveGUI_SphereDlg::ClickOnApply()
208 buttonApply->setFocus();
209 QAD_Application::getDesktop()->putInfo(tr(""));
210 if(mySimulationTopoDs.IsNull())
212 myGeomBase->EraseSimulationShape();
213 mySimulationTopoDs.Nullify();
216 myPrimitiveGUI->MakeSphereAndDisplay(myPoint1, myRadius);
221 //=================================================================================
222 // function : SelectionIntoArgument()
223 // purpose : Called when selection as changed or other case
224 //=================================================================================
225 void PrimitiveGUI_SphereDlg::SelectionIntoArgument()
227 myGeomBase->EraseSimulationShape();
228 myEditCurrentArgument->setText("");
229 QString aString = ""; /* name of selection */
231 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
233 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
234 GroupPoints->LineEdit1->setText("");
242 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
245 /* Constructor 1 treatment */
246 if(myEditCurrentArgument == GroupPoints->LineEdit1 && myGeomBase->VertexToPoint(S, myPoint1)) {
247 GroupPoints->LineEdit1->setText(aString);
252 mySimulationTopoDs = BRepPrimAPI_MakeSphere(myPoint1, myRadius).Shape();
253 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
259 //=================================================================================
260 // function : LineEditReturnPressed()
262 //=================================================================================
263 void PrimitiveGUI_SphereDlg::LineEditReturnPressed()
265 QLineEdit* send = (QLineEdit*)sender();
266 if(send == GroupPoints->LineEdit1)
267 myEditCurrentArgument = GroupPoints->LineEdit1;
271 GEOMBase_Skeleton::LineEditReturnPressed();
276 //=================================================================================
277 // function : SetEditCurrentArgument()
279 //=================================================================================
280 void PrimitiveGUI_SphereDlg::SetEditCurrentArgument()
282 if(myConstructorId != 0)
285 QPushButton* send = (QPushButton*)sender();
287 if(send == GroupPoints->PushButton1) {
288 GroupPoints->LineEdit1->setFocus();
289 myEditCurrentArgument = GroupPoints->LineEdit1;
290 mySelection->AddFilter(myVertexFilter);
291 this->SelectionIntoArgument();
297 //=================================================================================
298 // function : ActivateThisDialog()
300 //=================================================================================
301 void PrimitiveGUI_SphereDlg::ActivateThisDialog()
303 GEOMBase_Skeleton::ActivateThisDialog();
304 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
305 if(myConstructorId == 0)
306 mySelection->AddFilter(myVertexFilter);
307 if(!mySimulationTopoDs.IsNull())
308 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
313 //=================================================================================
314 // function : enterEvent()
316 //=================================================================================
317 void PrimitiveGUI_SphereDlg::enterEvent(QEvent* e)
319 if(GroupConstructors->isEnabled())
321 this->ActivateThisDialog();
326 //=================================================================================
327 // function : ValueChangedInSpinBox()
329 //=================================================================================
330 void PrimitiveGUI_SphereDlg::ValueChangedInSpinBox(double newValue)
332 myGeomBase->EraseSimulationShape();
333 mySimulationTopoDs.Nullify();
337 mySimulationTopoDs = BRepPrimAPI_MakeSphere(myPoint1, myRadius).Shape();
338 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);