// 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
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
//
//
#include "TransformationGUI_RotationDlg.h"
-#include <gp_Lin.hxx>
-#include <BRepBuilderAPI_Transform.hxx>
-#include <BRepAdaptor_Curve.hxx>
+#include "SUIT_Desktop.h"
+#include "SUIT_Session.h"
+#include "SalomeApp_Application.h"
+#include "LightApp_SelectionMgr.h"
+
+#include <qcheckbox.h>
+#include <qlabel.h>
+
+#include "GEOMImpl_Types.hxx"
#include "utilities.h"
// The dialog will by default be modeless, unless you set 'modal' to
// TRUE to construct a modal dialog.
//=================================================================================
-TransformationGUI_RotationDlg::TransformationGUI_RotationDlg(QWidget* parent, const char* name, TransformationGUI* theTransformationGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
- :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
+TransformationGUI_RotationDlg::TransformationGUI_RotationDlg
+ (GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, WFlags fl)
+ :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
+ WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
{
- QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_ROTATION")));
- QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
+ SUIT_ResourceMgr* aResMgr = myGeomGUI->getApp()->resourceMgr();
+ QPixmap image0 (aResMgr->loadPixmap("GEOM",tr("ICON_DLG_ROTATION")));
+ QPixmap image1 (aResMgr->loadPixmap("GEOM",tr("ICON_SELECT")));
+ QPixmap image2 (aResMgr->loadPixmap("GEOM",tr("ICON_DLG_ROTATION_THREE_POINTS")));
setCaption(tr("GEOM_ROTATION_TITLE"));
/***************************************************************/
GroupConstructors->setTitle(tr("GEOM_ROTATION"));
RadioButton1->setPixmap(image0);
- RadioButton2->close(TRUE);
+ RadioButton2->setPixmap(image2);
RadioButton3->close(TRUE);
- GroupPoints = new DlgRef_2Sel1Spin1Check(this, "GroupPoints");
+ GroupPoints = new DlgRef_4Sel1Spin2Check(this, "GroupPoints");
GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
- GroupPoints->TextLabel1->setText(tr("GEOM_OBJECT"));
+ GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
GroupPoints->TextLabel3->setText(tr("GEOM_ANGLE"));
- GroupPoints->CheckButton1->setText(tr("GEOM_REVERSE"));
+ GroupPoints->TextLabel4->setText(tr("GEOM_POINT_I").arg("1"));
+ GroupPoints->TextLabel5->setText(tr("GEOM_POINT_I").arg("2"));
+
+ GroupPoints->LineEdit1->setReadOnly(true);
+ GroupPoints->LineEdit2->setReadOnly(true);
+ GroupPoints->LineEdit4->setReadOnly(true);
+ GroupPoints->LineEdit5->setReadOnly(true);
GroupPoints->PushButton1->setPixmap(image1);
GroupPoints->PushButton2->setPixmap(image1);
+ GroupPoints->PushButton4->setPixmap(image1);
+ GroupPoints->PushButton5->setPixmap(image1);
+ GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
+ GroupPoints->CheckButton2->setText(tr("GEOM_REVERSE"));
- Layout1->addWidget(GroupPoints, 1, 0);
+ Layout1->addWidget(GroupPoints, 2, 0);
/***************************************************************/
+ double anAngle = 0;
+ double SpecificStep = 5;
+ /* min, max, step and decimals for spin boxes & initial values */
+ GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep, 3);
+ GroupPoints->SpinBox_DX->SetValue(anAngle);
+
+ // Activate Create a Copy mode
+ GroupPoints->CheckButton1->setChecked(true);
+ CreateCopyModeChanged(true);
+
+ /* signals and slots connections */
+ connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
+ connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
+ connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
+
+ connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
+ connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
+ connect(GroupPoints->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
+ connect(GroupPoints->PushButton5, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
+
+ connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
+ connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
+
+ connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
+ connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
+ connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
+
+ connect(myGeomGUI->getApp()->selectionMgr(),
+ SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
+
+ setHelpFileName("rotation.htm");
- /* Initialisations */
- myTransformationGUI = theTransformationGUI;
Init();
}
{
/* init variables */
myEditCurrentArgument = GroupPoints->LineEdit1;
-
- myAngle = 0.0;
- myOkBase = myOkAxis = false;
-
- myEdgeFilter = new GEOM_ShapeTypeFilter(TopAbs_EDGE, myGeom);
-
- double SpecificStep = 5;
- /* min, max, step and decimals for spin boxes & initial values */
- GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, SpecificStep, 3);
- GroupPoints->SpinBox_DX->SetValue(myAngle);
-
- /* signals and slots connections */
- connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
- connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
-
- connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
- connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
-
- connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
- connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
-
- connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
- connect(GroupPoints->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(ReverseAngle(int)));
+ GroupPoints->LineEdit2->clear();
- connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
-
- /* displays Dialog */
- GroupPoints->show();
- this->show();
-
- return;
+ myAxis = myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
+
+ initName( tr( "GEOM_ROTATION" ) );
+ ConstructorsClicked( 0 );
}
+//=================================================================================
+// function : ConstructorsClicked()
+// purpose : Radio button management
+//=================================================================================
+void TransformationGUI_RotationDlg::ConstructorsClicked(int constructorId)
+{
+ disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
+
+ myEditCurrentArgument = GroupPoints->LineEdit1;
+ globalSelection();
+
+ switch (constructorId)
+ {
+ case 0: /* rotation an object angle and axis */
+ {
+ GroupPoints->ShowRows(2,3,false);
+ resize(0,0);
+ GroupPoints->TextLabel2->setText(tr("GEOM_AXIS"));
+ GroupPoints->LineEdit2->clear();
+ GroupPoints->ShowRows(4,4,true);
+ myAxis = GEOM::GEOM_Object::_nil();
+ break;
+ }
+ case 1: /* rotation an object by 3 points */
+ {
+ GroupPoints->ShowRows(4,4,false);
+ resize(0,0);
+ GroupPoints->ShowRows(2,3,true);
+ GroupPoints->TextLabel2->setText(tr("GEOM_CENTRAL_POINT"));
+ GroupPoints->TextLabel4->setText(tr("GEOM_POINT_I").arg("1"));
+ GroupPoints->TextLabel5->setText(tr("GEOM_POINT_I").arg("2"));
+ GroupPoints->LineEdit2->clear();
+ GroupPoints->LineEdit4->clear();
+ GroupPoints->LineEdit5->clear();
+ myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
+ break;
+ }
+ }
+
+ myEditCurrentArgument->setFocus();
+ connect(myGeomGUI->getApp()->selectionMgr(),
+ SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
+}
//=================================================================================
// function : ClickOnOk()
//=================================================================================
void TransformationGUI_RotationDlg::ClickOnOk()
{
- this->ClickOnApply();
- ClickOnCancel();
- return;
+ if ( ClickOnApply() )
+ ClickOnCancel();
}
// function : ClickOnApply()
// purpose :
//=================================================================================
-void TransformationGUI_RotationDlg::ClickOnApply()
+bool TransformationGUI_RotationDlg::ClickOnApply()
{
- buttonApply->setFocus();
- QAD_Application::getDesktop()->putInfo(tr(""));
- if (mySimulationTopoDs.IsNull())
- return;
- myGeomBase->EraseSimulationShape();
- mySimulationTopoDs.Nullify();
-
- if(myOkBase && myOkAxis)
- myTransformationGUI->MakeRotationAndDisplay(myGeomShape, myLoc, myDir, myAngle*PI180);
- return;
+ if ( !onAccept( GroupPoints->CheckButton1->isChecked()) )
+ return false;
+
+ initName();
+ ConstructorsClicked( getConstructorId() );
+ return true;
}
//=================================================================================
void TransformationGUI_RotationDlg::SelectionIntoArgument()
{
- myGeomBase->EraseSimulationShape();
- mySimulationTopoDs.Nullify();
myEditCurrentArgument->setText("");
- QString aString = ""; /* name of selection */
+ QString aName;
- int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
- if(nbSel != 1) {
- if(myEditCurrentArgument == GroupPoints->LineEdit1)
- myOkBase = false;
- else if(myEditCurrentArgument == GroupPoints->LineEdit2)
- myOkAxis = false;
- return;
- }
+ if(myEditCurrentArgument == GroupPoints->LineEdit1)
+ {
+ int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
+ if(aNbSel < 1)
+ {
+ myObjects.length(0);
+ return;
+ }
+ GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
+ if (!myObjects.length())
+ return;
+ }
+ else
+ {
+ if(IObjectCount() != 1)
+ {
+ if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0)
+ myAxis = GEOM::GEOM_Object::_nil();
+ else if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
+ myCentPoint = GEOM::GEOM_Object::_nil();
+ else if(myEditCurrentArgument == GroupPoints->LineEdit4)
+ myPoint1 = GEOM::GEOM_Object::_nil();
+ else if(myEditCurrentArgument == GroupPoints->LineEdit5)
+ myPoint2 = GEOM::GEOM_Object::_nil();
+ return;
+ }
+
+ Standard_Boolean testResult = Standard_False;
+ GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
+ if(!testResult || CORBA::is_nil( aSelectedObject ))
+ return;
+
+ if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0)
+ myAxis = aSelectedObject;
+ else if(myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
+ myCentPoint = aSelectedObject;
+ else if(myEditCurrentArgument == GroupPoints->LineEdit4)
+ myPoint1 = aSelectedObject;
+ else if(myEditCurrentArgument == GroupPoints->LineEdit5)
+ myPoint2 = aSelectedObject;
+
+ aName = GEOMBase::GetName( aSelectedObject );
+ }
+ myEditCurrentArgument->setText( aName );
- // nbSel == 1
- TopoDS_Shape S;
- Standard_Boolean testResult;
- Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
- if(!myGeomBase->GetTopoFromSelection(mySelection, S))
- return;
-
- if(myEditCurrentArgument == GroupPoints->LineEdit1) {
- myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
- if(!testResult)
- return;
- myEditCurrentArgument->setText(aString);
- myOkBase = true;
- myBase = S;
- }
- else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
- BRepAdaptor_Curve curv(TopoDS::Edge(S));
- myDir = curv.Line().Direction();
- myLoc = curv.Line().Location();
- myEditCurrentArgument->setText(aString);
- myOkAxis = true;
- }
-
- if(myOkBase && myOkAxis)
- this->MakeRotationSimulationAndDisplay();
- return;
+ displayPreview();
}
void TransformationGUI_RotationDlg::SetEditCurrentArgument()
{
QPushButton* send = (QPushButton*)sender();
- mySelection->ClearFilters();
-
+
if(send == GroupPoints->PushButton1) {
- GroupPoints->LineEdit1->setFocus();
myEditCurrentArgument = GroupPoints->LineEdit1;
+ globalSelection();
}
else if(send == GroupPoints->PushButton2) {
- GroupPoints->LineEdit2->setFocus();
myEditCurrentArgument = GroupPoints->LineEdit2;
- mySelection->AddFilter(myEdgeFilter);
+ getConstructorId() == 0 ? globalSelection( GEOM_LINE ) :
+ globalSelection( GEOM_POINT );
}
- this->SelectionIntoArgument();
-
- return;
+ else if (send == GroupPoints->PushButton4)
+ {
+ myEditCurrentArgument = GroupPoints->LineEdit4;
+ globalSelection( GEOM_POINT );
+ }
+ else if (send == GroupPoints->PushButton5)
+ {
+ myEditCurrentArgument = GroupPoints->LineEdit5;
+ globalSelection( GEOM_POINT );
+ }
+
+ myEditCurrentArgument->setFocus();
+ SelectionIntoArgument();
}
void TransformationGUI_RotationDlg::LineEditReturnPressed()
{
QLineEdit* send = (QLineEdit*)sender();
- if(send == GroupPoints->LineEdit1)
- myEditCurrentArgument = GroupPoints->LineEdit1;
- else if (send == GroupPoints->LineEdit2)
- myEditCurrentArgument = GroupPoints->LineEdit2;
- else
- return;
-
- GEOMBase_Skeleton::LineEditReturnPressed();
- return;
+ if(send == GroupPoints->LineEdit1 ||
+ send == GroupPoints->LineEdit2)
+ {
+ myEditCurrentArgument = send;
+ GEOMBase_Skeleton::LineEditReturnPressed();
+ }
}
void TransformationGUI_RotationDlg::ActivateThisDialog()
{
GEOMBase_Skeleton::ActivateThisDialog();
- connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
- GroupPoints->LineEdit1->setFocus();
- myEditCurrentArgument = GroupPoints->LineEdit1;
- if(!mySimulationTopoDs.IsNull())
- myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
- return;
+ connect(myGeomGUI->getApp()->selectionMgr(),
+ SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
+
+ ConstructorsClicked( getConstructorId() );
}
//=================================================================================
void TransformationGUI_RotationDlg::enterEvent(QEvent* e)
{
- if (GroupConstructors->isEnabled())
- return;
- this->ActivateThisDialog();
- return;
+ if (!GroupConstructors->isEnabled())
+ ActivateThisDialog();
}
// function : ValueChangedInSpinBox()
// purpose :
//=================================================================================
-void TransformationGUI_RotationDlg::ValueChangedInSpinBox(double newValue)
+void TransformationGUI_RotationDlg::ValueChangedInSpinBox()
{
- myAngle = newValue;
- if(myOkBase && myOkAxis)
- MakeRotationSimulationAndDisplay();
- return;
+ displayPreview();
}
//=================================================================================
-// function : MakeRotationSimulationAndDisplay()
+// function : createOperation
// purpose :
//=================================================================================
-void TransformationGUI_RotationDlg::MakeRotationSimulationAndDisplay()
+GEOM::GEOM_IOperations_ptr TransformationGUI_RotationDlg::createOperation()
{
- myGeomBase->EraseSimulationShape();
- mySimulationTopoDs.Nullify();
-
- try {
- gp_Ax1 AX(myLoc, myDir);
- gp_Trsf theTransformation;
- theTransformation.SetRotation(AX, myAngle*PI180);
- BRepBuilderAPI_Transform myBRepTransformation(myBase, theTransformation, Standard_False);
- this->mySimulationTopoDs = myBRepTransformation.Shape();
- myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
- }
- catch(Standard_Failure) {
- MESSAGE("Exception catched in MakeRotationSimulationAndDisplay");
- return;
- }
- return;
+ return getGeomEngine()->GetITransformOperations( getStudyId() );
}
//=================================================================================
-// function : ReverseAngle()
-// purpose : 'state' not used here
+// function : isValid
+// purpose :
+//=================================================================================
+bool TransformationGUI_RotationDlg::isValid( QString& msg )
+{
+ switch (getConstructorId())
+ {
+ case 0:
+ {
+ return !(myObjects.length() == 0 || myAxis->_is_nil());
+ break;
+ }
+ case 1:
+ {
+ return !(myObjects.length() == 0 || myCentPoint->_is_nil() || myPoint1->_is_nil() || myPoint2->_is_nil() );
+ break;
+ }
+ default: return false;
+ }
+}
+
+
+//=================================================================================
+// function : execute
+// purpose :
+//=================================================================================
+bool TransformationGUI_RotationDlg::execute( ObjectList& objects )
+{
+ bool res = false;
+ bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
+
+ GEOM::GEOM_Object_var anObj;
+
+ switch ( getConstructorId() )
+ {
+ case 0 :
+ {
+ if (toCreateCopy)
+ for (int i = 0; i < myObjects.length(); i++)
+ {
+ anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->RotateCopy( myObjects[i], myAxis, GetAngle() * PI180 );
+ if ( !anObj->_is_nil() )
+ objects.push_back( anObj._retn() );
+ }
+ else
+ for (int i = 0; i < myObjects.length(); i++)
+ {
+ anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->Rotate( myObjects[i], myAxis, GetAngle() * PI180 );
+ if ( !anObj->_is_nil() )
+ objects.push_back( anObj._retn() );
+ }
+ res = true;
+ break;
+ }
+ case 1 :
+ {
+ if (toCreateCopy)
+ for (int i = 0; i < myObjects.length(); i++)
+ {
+ anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->RotateThreePointsCopy( myObjects[i], myCentPoint, myPoint1, myPoint2 );
+ if ( !anObj->_is_nil() )
+ objects.push_back( anObj._retn() );
+ }
+ else
+ for (int i = 0; i < myObjects.length(); i++)
+ {
+ anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->RotateThreePoints( myObjects[i], myCentPoint, myPoint1, myPoint2 );
+ if ( !anObj->_is_nil() )
+ objects.push_back( anObj._retn() );
+ }
+ res = true;
+ break;
+ }
+ }
+
+ return res;
+}
+
+
+//=================================================================================
+// function : closeEvent
+// purpose :
+//=================================================================================
+void TransformationGUI_RotationDlg::closeEvent( QCloseEvent* e )
+{
+ GEOMBase_Skeleton::closeEvent( e );
+}
+
+
+//=================================================================================
+// function : GetAngle()
+// purpose :
+//=================================================================================
+double TransformationGUI_RotationDlg::GetAngle() const
+{
+ return GroupPoints->SpinBox_DX->GetValue();
+}
+
+
+//=================================================================================
+// function : CreateCopyModeChanged()
+// purpose :
+//=================================================================================
+void TransformationGUI_RotationDlg::CreateCopyModeChanged(bool isCreateCopy)
+{
+ this->GroupBoxName->setEnabled(isCreateCopy);
+}
+
+
+//=================================================================================
+// function : onReverse()
+// purpose :
//=================================================================================
-void TransformationGUI_RotationDlg::ReverseAngle(int state)
+void TransformationGUI_RotationDlg::onReverse()
{
- myAngle = -myAngle;
- GroupPoints->SpinBox_DX->SetValue(myAngle);
- if(myOkBase && myOkAxis)
- MakeRotationSimulationAndDisplay();
- return;
+ double anOldValue = GroupPoints->SpinBox_DX->GetValue();
+ GroupPoints->SpinBox_DX->SetValue( -anOldValue );
}