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 : TransformationGUI_MultiTranslationDlg.cxx
25 // Author : Damien COQUERET
30 #include "TransformationGUI_MultiRotationDlg.h"
33 #include <Precision.hxx>
34 #include <BRepBuilderAPI_MakeVertex.hxx>
35 #include <GeomAPI_ProjectPointOnCurve.hxx>
36 #include <BRepAdaptor_Curve.hxx>
37 #include <BRep_Builder.hxx>
38 #include <BRepGProp.hxx>
39 #include <GProp_GProps.hxx>
40 #include <TopoDS_Compound.hxx>
41 #include <Geom_Line.hxx>
42 #include <BRepBuilderAPI_Transform.hxx>
43 #include "QAD_Config.h"
45 //=================================================================================
46 // class : TransformationGUI_MultiRotationDlg()
47 // purpose : Constructs a TransformationGUI_MultiRotationDlg which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 TransformationGUI_MultiRotationDlg::TransformationGUI_MultiRotationDlg(QWidget* parent, const char* name, TransformationGUI* theTransformationGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
53 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
55 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_MULTIROTATION_SIMPLE")));
56 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_MULTIROTATION_DOUBLE")));
57 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
59 setCaption(tr("GEOM_MULTIROTATION_TITLE"));
61 /***************************************************************/
62 GroupConstructors->setTitle(tr("GEOM_MULTIROTATION"));
63 RadioButton1->setPixmap(image0);
64 RadioButton2->setPixmap(image1);
65 RadioButton3->close(TRUE);
67 GroupPoints = new DlgRef_2Sel1Spin(this, "GroupPoints");
68 GroupPoints->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_SIMPLE"));
69 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
70 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
71 GroupPoints->TextLabel3->setText(tr("GEOM_NB_TIMES"));
72 GroupPoints->PushButton1->setPixmap(image2);
73 GroupPoints->PushButton2->setPixmap(image2);
75 GroupDimensions = new DlgRef_2Sel4Spin1Check(this, "GroupDimensions");
76 GroupDimensions->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_DOUBLE"));
77 GroupDimensions->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
78 GroupDimensions->TextLabel2->setText(tr("GEOM_VECTOR"));
79 GroupDimensions->TextLabel3->setText(tr("GEOM_ANGLE"));
80 GroupDimensions->TextLabel4->setText(tr("GEOM_NB_TIMES"));
81 GroupDimensions->TextLabel5->setText(tr("GEOM_STEP"));
82 GroupDimensions->TextLabel6->setText(tr("GEOM_NB_TIMES"));
83 GroupDimensions->CheckButton1->setText(tr("GEOM_REVERSE"));
84 GroupDimensions->PushButton1->setPixmap(image2);
85 GroupDimensions->PushButton2->setPixmap(image2);
87 Layout1->addWidget(GroupPoints, 1, 0);
88 Layout1->addWidget(GroupDimensions, 1, 0);
89 /***************************************************************/
92 myTransformationGUI = theTransformationGUI;
97 //=================================================================================
98 // function : ~TransformationGUI_MultiRotationDlg()
99 // purpose : Destroys the object and frees any allocated resources
100 //=================================================================================
101 TransformationGUI_MultiRotationDlg::~TransformationGUI_MultiRotationDlg()
103 // no need to delete child widgets, Qt does it all for us
107 //=================================================================================
110 //=================================================================================
111 void TransformationGUI_MultiRotationDlg::Init()
115 myEditCurrentArgument = GroupPoints->LineEdit1;
121 myOkBase = myOkDir = false;
123 myEdgeFilter = new GEOM_ShapeTypeFilter(TopAbs_EDGE, myGeom);
125 /* Get setting of step value from file configuration */
126 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
127 step = St.toDouble();
129 double SpecificStep1 = 5;
130 double SpecificStep2 = 1;
131 /* min, max, step and decimals for spin boxes & initial values */
132 GroupPoints->SpinBox_DX->RangeStepAndValidator(1.0, 999.999, SpecificStep2, 3);
133 GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
135 GroupDimensions->SpinBox_DX1->RangeStepAndValidator(-999.999, 999.999, SpecificStep1, 3);
136 GroupDimensions->SpinBox_DY1->RangeStepAndValidator(1.0, 999.999, SpecificStep2, 3);
137 GroupDimensions->SpinBox_DX2->RangeStepAndValidator(-999.999, 999.999, step, 3);
138 GroupDimensions->SpinBox_DY2->RangeStepAndValidator(1.0, 999.999, SpecificStep2, 3);
139 GroupDimensions->SpinBox_DX1->SetValue(myAng);
140 GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
141 GroupDimensions->SpinBox_DX2->SetValue(myStep);
142 GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
144 /* signals and slots connections */
145 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
146 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
147 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
149 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
150 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
151 connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
152 connect(GroupDimensions->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
154 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
155 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
156 connect(GroupDimensions->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
157 connect(GroupDimensions->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
159 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
160 connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
161 connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
162 connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
163 connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
165 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
166 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX1, SLOT(SetStep(double)));
167 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY1, SLOT(SetStep(double)));
168 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX2, SLOT(SetStep(double)));
169 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY2, SLOT(SetStep(double)));
171 connect(GroupDimensions->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(ReverseAngle(int)));
173 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
175 /* displays Dialog */
176 GroupDimensions->hide();
184 //=================================================================================
185 // function : ConstructorsClicked()
186 // purpose : Radio button management
187 //=================================================================================
188 void TransformationGUI_MultiRotationDlg::ConstructorsClicked(int constructorId)
190 myConstructorId = constructorId;
191 mySelection->ClearFilters();
192 myGeomBase->EraseSimulationShape();
193 mySimulationTopoDs.Nullify();
194 disconnect(mySelection, 0, this, 0);
199 myOkBase = myOkDir = false;
201 switch (constructorId)
203 case 0: /* Rotate simple */
205 GroupDimensions->hide();
209 myEditCurrentArgument = GroupPoints->LineEdit1;
210 GroupPoints->LineEdit1->setText("");
211 GroupPoints->LineEdit2->setText("");
213 GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
215 /* filter for next selection */
216 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
219 case 1: /* Rotate double */
223 GroupDimensions->show();
225 myEditCurrentArgument = GroupDimensions->LineEdit1;
226 GroupDimensions->LineEdit1->setText("");
227 GroupDimensions->LineEdit2->setText("");
229 GroupDimensions->SpinBox_DX1->SetValue(myAng);
230 GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
231 GroupDimensions->SpinBox_DX2->SetValue(myStep);
232 GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
234 /* filter for next selection */
235 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
243 //=================================================================================
244 // function : ClickOnOk()
246 //=================================================================================
247 void TransformationGUI_MultiRotationDlg::ClickOnOk()
249 this->ClickOnApply();
255 //=================================================================================
256 // function : ClickOnApply()
258 //=================================================================================
259 void TransformationGUI_MultiRotationDlg::ClickOnApply()
261 QAD_Application::getDesktop()->putInfo(tr(""));
262 if (mySimulationTopoDs.IsNull())
264 myGeomBase->EraseSimulationShape();
265 mySimulationTopoDs.Nullify();
267 if(myConstructorId == 0) {
268 if(myOkBase && myOkDir)
269 myTransformationGUI->MakeMultiRotation1DAndDisplay(myGeomShape, myDir, myLoc, myNbTimes1);
271 else if(myConstructorId == 1) {
272 if(myOkBase && myOkDir)
273 myTransformationGUI->MakeMultiRotation2DAndDisplay(myGeomShape, myDir, myLoc, myAng, myNbTimes1, myStep, myNbTimes2);
279 //=================================================================================
280 // function : SelectionIntoArgument()
281 // purpose : Called when selection as changed or other case
282 //=================================================================================
283 void TransformationGUI_MultiRotationDlg::SelectionIntoArgument()
285 myGeomBase->EraseSimulationShape();
286 mySimulationTopoDs.Nullify();
287 myEditCurrentArgument->setText("");
288 QString aString = ""; /* name of selection */
290 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
292 if(myEditCurrentArgument == GroupPoints->LineEdit1 || myEditCurrentArgument == GroupDimensions->LineEdit1)
294 else if(myEditCurrentArgument == GroupPoints->LineEdit2 || myEditCurrentArgument == GroupDimensions->LineEdit2)
301 Standard_Boolean testResult;
302 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
303 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
306 if(myEditCurrentArgument == GroupPoints->LineEdit1 || myEditCurrentArgument == GroupDimensions->LineEdit1) {
307 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
310 myEditCurrentArgument->setText(aString);
314 else if(myEditCurrentArgument == GroupPoints->LineEdit2 || myEditCurrentArgument == GroupDimensions->LineEdit2) {
315 BRepAdaptor_Curve curv(TopoDS::Edge(S));
316 myDir = curv.Line().Direction();
317 myLoc = curv.Line().Location();
318 myEditCurrentArgument->setText(aString);
322 if(myOkBase && myOkDir)
323 this->MakeMultiRotationSimulationAndDisplay();
328 //=================================================================================
329 // function : SetEditCurrentArgument()
331 //=================================================================================
332 void TransformationGUI_MultiRotationDlg::SetEditCurrentArgument()
334 QPushButton* send = (QPushButton*)sender();
335 mySelection->ClearFilters();
337 if(send == GroupPoints->PushButton1) {
338 GroupPoints->LineEdit1->setFocus();
339 myEditCurrentArgument = GroupPoints->LineEdit1;
341 else if(send == GroupPoints->PushButton2) {
342 GroupPoints->LineEdit2->setFocus();
343 myEditCurrentArgument = GroupPoints->LineEdit2;
344 mySelection->AddFilter(myEdgeFilter);
346 else if(send == GroupDimensions->PushButton1) {
347 GroupDimensions->LineEdit1->setFocus();
348 myEditCurrentArgument = GroupDimensions->LineEdit1;
350 else if(send == GroupDimensions->PushButton2) {
351 GroupDimensions->LineEdit2->setFocus();
352 myEditCurrentArgument = GroupDimensions->LineEdit2;
353 mySelection->AddFilter(myEdgeFilter);
355 this->SelectionIntoArgument();
361 //=================================================================================
362 // function : LineEditReturnPressed()
364 //=================================================================================
365 void TransformationGUI_MultiRotationDlg::LineEditReturnPressed()
367 QLineEdit* send = (QLineEdit*)sender();
368 if(send == GroupPoints->LineEdit1)
369 myEditCurrentArgument = GroupPoints->LineEdit1;
370 else if (send == GroupPoints->LineEdit2)
371 myEditCurrentArgument = GroupPoints->LineEdit2;
372 else if (send == GroupDimensions->LineEdit1)
373 myEditCurrentArgument = GroupDimensions->LineEdit1;
374 else if (send == GroupDimensions->LineEdit2)
375 myEditCurrentArgument = GroupDimensions->LineEdit2;
379 GEOMBase_Skeleton::LineEditReturnPressed();
384 //=================================================================================
385 // function : ActivateThisDialog()
387 //=================================================================================
388 void TransformationGUI_MultiRotationDlg::ActivateThisDialog()
390 GEOMBase_Skeleton::ActivateThisDialog();
391 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
393 if(myConstructorId == 0) {
394 GroupPoints->LineEdit1->setFocus();
395 myEditCurrentArgument = GroupPoints->LineEdit1;
397 else if(myConstructorId == 1) {
398 GroupDimensions->LineEdit1->setFocus();
399 myEditCurrentArgument = GroupDimensions->LineEdit1;
402 if(!mySimulationTopoDs.IsNull())
403 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
408 //=================================================================================
409 // function : enterEvent()
411 //=================================================================================
412 void TransformationGUI_MultiRotationDlg::enterEvent(QEvent* e)
414 if (GroupConstructors->isEnabled())
416 this->ActivateThisDialog();
421 //=================================================================================
422 // function : ValueChangedInSpinBox()
424 //=================================================================================
425 void TransformationGUI_MultiRotationDlg::ValueChangedInSpinBox(double newValue)
427 myGeomBase->EraseSimulationShape();
428 mySimulationTopoDs.Nullify();
429 QObject* send = (QObject*)sender();
431 if(send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DY1)
432 myNbTimes1 = newValue;
433 else if(send == GroupDimensions->SpinBox_DX1)
435 else if(send == GroupDimensions->SpinBox_DX2)
437 else if(send == GroupDimensions->SpinBox_DY2)
438 myNbTimes2 = newValue;
440 if(myOkBase && myOkDir)
441 this->MakeMultiRotationSimulationAndDisplay();
446 //=================================================================================
447 // function : ReverseAngle()
448 // purpose : 'state' not used here
449 //=================================================================================
450 void TransformationGUI_MultiRotationDlg::ReverseAngle(int state)
453 if(myConstructorId == 0)
454 GroupPoints->SpinBox_DX->SetValue(myAng);
455 else if(myConstructorId == 1)
456 GroupDimensions->SpinBox_DX1->SetValue(myAng);
458 if(myOkBase && myOkDir)
459 this->MakeMultiRotationSimulationAndDisplay();
464 //=================================================================================
465 // function : MakeMultiRotationSimulationAndDisplay()
467 //=================================================================================
468 void TransformationGUI_MultiRotationDlg::MakeMultiRotationSimulationAndDisplay()
470 myGeomBase->EraseSimulationShape();
471 mySimulationTopoDs.Nullify();
474 Standard_Real DX, DY, DZ;
475 gp_Trsf theTransformation;
476 gp_Trsf theTransformation1;
477 gp_Trsf theTransformation2;
480 TopoDS_Compound compound;
483 B.MakeCompound(compound);
485 if(myBase.ShapeType() == TopAbs_VERTEX)
486 myGeomBase->VertexToPoint(myBase, myPoint);
487 else if(myBase.ShapeType() == TopAbs_EDGE || myBase.ShapeType() == TopAbs_WIRE) {
488 BRepGProp::LinearProperties(myBase, System);
489 myPoint = System.CentreOfMass();
491 else if(myBase.ShapeType() == TopAbs_FACE || myBase.ShapeType() == TopAbs_SHELL) {
492 BRepGProp::SurfaceProperties(myBase, System);
493 myPoint = System.CentreOfMass();
496 BRepGProp::VolumeProperties(myBase, System);
497 myPoint = System.CentreOfMass();
500 TopoDS_Shape S = BRepBuilderAPI_MakeVertex(myPoint).Shape();
503 switch (myConstructorId)
507 gp_Ax1 AX1(myLoc, myDir);
508 Standard_Real angle = 360/myNbTimes1;
509 for(i = 0; i < myNbTimes1; i++) {
510 theTransformation.SetRotation(AX1, i*angle*PI180);
511 BRepBuilderAPI_Transform myBRepTransformation(S, theTransformation, Standard_False);
512 B.Add(compound, myBRepTransformation.Shape());
514 mySimulationTopoDs = compound;
515 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
520 gp_Ax1 AX2(myLoc, myDir);
521 Handle(Geom_Line) Line = new Geom_Line(AX2);
522 gp_Pnt P2 = GeomAPI_ProjectPointOnCurve(myPoint, Line);
523 if(myPoint.IsEqual(P2, Precision::Confusion()))
526 gp_Vec Vec(P2, myPoint);
529 for(i = 0; i < myNbTimes2; i++) {
530 for(j = 0; j < myNbTimes1; j++) {
531 DX = i * myStep * Vec.X();
532 DY = i * myStep * Vec.Y();
533 DZ = i * myStep * Vec.Z();
534 myVec.SetCoord(DX, DY, DZ);
536 theTransformation1.SetTranslation(myVec);
537 theTransformation2.SetRotation(AX2, j*myAng*PI180);
538 BRepBuilderAPI_Transform myBRepTransformation1(S, theTransformation1, Standard_False);
539 BRepBuilderAPI_Transform myBRepTransformation2(myBRepTransformation1.Shape(), theTransformation2, Standard_False);
540 B.Add(compound, myBRepTransformation2.Shape());
543 mySimulationTopoDs = compound;
544 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
549 catch(Standard_Failure) {
550 MESSAGE("Exception catched in MakeMultitranslationSimulationAndDisplay");