-// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+
// GEOM GEOMGUI : GUI for Geometry component
// File : TransformationGUI_TranslationDlg.cxx
// Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
#include <SUIT_Session.h>
#include <SUIT_ResourceMgr.h>
+#include <SUIT_Desktop.h>
+#include <SUIT_ViewWindow.h>
+#include <SUIT_ViewManager.h>
#include <SalomeApp_Application.h>
#include <LightApp_SelectionMgr.h>
+#include <GEOM_AISVector.hxx>
+#include <SOCC_Prs.h>
+#include <SOCC_ViewModel.h>
// OCCT Includes
#include <TopoDS_Shape.hxx>
#include <TopoDS_Edge.hxx>
+#include <TopoDS_Vertex.hxx>
#include <TopoDS.hxx>
#include <TopExp.hxx>
#include <TColStd_IndexedMapOfInteger.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
+#include <ShapeAnalysis_Edge.hxx>
+#include <BRep_Tool.hxx>
+#include <BRepBuilderAPI_MakeEdge.hxx>
+#include <BRep_Builder.hxx>
#include <GEOMImpl_Types.hxx>
// Activate Create a Copy mode
GroupPoints->CheckBox2->setChecked(true);
- CreateCopyModeChanged(true);
+ CreateCopyModeChanged();
Init();
}
double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100);
// min, max, step and decimals for spin boxes & initial values
- initSpinBox(GroupPoints->SpinBox1, COORD_MIN, COORD_MAX, step, 3); // VSR: TODO: DBL_DIGITS_DISPLAY
- initSpinBox(GroupPoints->SpinBox2, COORD_MIN, COORD_MAX, step, 3); // VSR: TODO: DBL_DIGITS_DISPLAY
- initSpinBox(GroupPoints->SpinBox3, COORD_MIN, COORD_MAX, step, 3); // VSR: TODO: DBL_DIGITS_DISPLAY
+ initSpinBox(GroupPoints->SpinBox1, COORD_MIN, COORD_MAX, step, "length_precision" );
+ initSpinBox(GroupPoints->SpinBox2, COORD_MIN, COORD_MAX, step, "length_precision" );
+ initSpinBox(GroupPoints->SpinBox3, COORD_MIN, COORD_MAX, step, "length_precision" );
GroupPoints->SpinBox1->setValue(0.0);
GroupPoints->SpinBox2->setValue(0.0);
GroupPoints->LineEdit2->setText("");
GroupPoints->LineEdit3->setText("");
- myVector = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
+ myObjects.clear();
+ myVector.nullify();
+ myPoint1.nullify();
+ myPoint2.nullify();
mainFrame()->GroupBoxPublish->show();
connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
- connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); //@ Delete ?
-
connect(GroupPoints->SpinBox1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
connect(GroupPoints->SpinBox2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
connect(GroupPoints->SpinBox3, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
- connect(GroupPoints->CheckBox1, SIGNAL(toggled(bool)), this, SLOT(ActivateDistanceChanged(bool)));
- connect(GroupPoints->CheckBox2, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
+ connect(GroupPoints->CheckBox1, SIGNAL(toggled(bool)), this, SLOT(ActivateDistanceChanged()));
+ connect(GroupPoints->CheckBox2, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged()));
initName(tr("GEOM_TRANSLATION"));
GroupPoints->CheckBox1->hide();
- myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
+ myPoint1.nullify();
+ myPoint2.nullify();
GroupPoints->PushButton1->click();
}
GroupPoints->CheckBox1->show();
- myVector = GEOM::GEOM_Object::_nil();
- ActivateDistanceChanged(GroupPoints->CheckBox1->isChecked());
+ myVector.nullify();
+ ActivateDistanceChanged();
GroupPoints->PushButton1->click();
}
return false;
initName();
+
+ myObjects.clear();
+ myEditCurrentArgument = GroupPoints->LineEdit1;
+ myEditCurrentArgument->setText("");
+ myGeomGUI->getApp()->selectionMgr()->clearSelected();
+
// activate selection and connect selection manager
ConstructorsClicked(getConstructorId());
return true;
void TransformationGUI_TranslationDlg::SelectionIntoArgument()
{
erasePreview();
- myEditCurrentArgument->setText("");
- if (myEditCurrentArgument == GroupPoints->LineEdit1)
- myObjects.length(0);
- else if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
- myPoint1 = GEOM::GEOM_Object::_nil();
- else if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2)
- myVector = GEOM::GEOM_Object::_nil();
- else if (myEditCurrentArgument == GroupPoints->LineEdit3)
- myPoint2 = GEOM::GEOM_Object::_nil();
-
- LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
- SALOME_ListIO aSelList;
- aSelMgr->selectedObjects(aSelList);
-
- QString aName;
-
- if (myEditCurrentArgument == GroupPoints->LineEdit1) {
- int aNbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aName);
- if (aNbSel < 1)
- return;
-
- GEOMBase::ConvertListOfIOInListOfGO(aSelList, myObjects);
- if (!myObjects.length())
- return;
+ if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
+ myObjects = getSelected( TopAbs_SHAPE, -1 );
+ if ( !myObjects.isEmpty() ) {
+ QString aName = myObjects.count() > 1 ? QString( "%1_objects").arg( myObjects.count() ) : GEOMBase::GetName( myObjects[0].get() );
+ myEditCurrentArgument->setText( aName );
+ }
else {
- myEditCurrentArgument->setText(aName);
-
- // here we do not switch to the next field, because multiple objects can be selected
- /*
- if (getConstructorId() == 1) {
- if (myPoint1->_is_nil())
- GroupPoints->PushButton2->click();
- }
- else if (getConstructorId() == 2) {
- if (myVector->_is_nil())
- GroupPoints->PushButton2->click();
- }
- */
+ myEditCurrentArgument->setText("");
}
}
else {
- if (aSelList.Extent() != 1)
- return;
-
- // nbSel == 1
- Standard_Boolean testResult = Standard_False;
- GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
-
- if (!testResult || CORBA::is_nil(aSelectedObject))
- return;
-
- aName = GEOMBase::GetName(aSelectedObject);
-
- // Get Selected object if selected subshape
+ TopAbs_ShapeEnum aNeedType = ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2 ) ?
+ TopAbs_EDGE : TopAbs_VERTEX;
+ GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
TopoDS_Shape aShape;
- if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
- {
- TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
- if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2)
- aNeedType = TopAbs_EDGE;
-
- TColStd_IndexedMapOfInteger aMap;
- aSelMgr->GetIndexes(aSelList.First(), aMap);
- if (aMap.Extent() == 1)
- {
- int anIndex = aMap(1);
- if (aNeedType == TopAbs_EDGE)
- aName += QString(":edge_%1").arg(anIndex);
- else
- aName += QString(":vertex_%1").arg(anIndex);
-
- //Find SubShape Object in Father
- GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
-
- if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
- GEOM::GEOM_IShapesOperations_var aShapesOp =
- getGeomEngine()->GetIShapesOperations(getStudyId());
- aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
- }
- else {
- aSelectedObject = aFindedObject;
- }
+ if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
+ QString aName = GEOMBase::GetName( aSelectedObject.get() );
+ myEditCurrentArgument->setText( aName );
+ if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
+ if ( getConstructorId() == 1 ) {
+ myPoint1 = aSelectedObject;
+ if ( !myPoint2 )
+ GroupPoints->PushButton3->click();
+ else if ( myObjects.isEmpty() )
+ GroupPoints->PushButton1->click();
+ }
+ else if ( getConstructorId() == 2 ) {
+ myVector = aSelectedObject;
+ if ( myObjects.isEmpty() )
+ GroupPoints->PushButton1->click();
+ }
}
- else // Global Selection
- {
- if (aShape.ShapeType() != aNeedType) {
- aSelectedObject = GEOM::GEOM_Object::_nil();
- aName = "";
- }
+ else if ( myEditCurrentArgument == GroupPoints->LineEdit3 ) {
+ myPoint2 = aSelectedObject;
+ if ( myObjects.isEmpty() )
+ GroupPoints->PushButton1->click();
+ else if ( !myPoint1 )
+ GroupPoints->PushButton2->click();
}
}
-
- myEditCurrentArgument->setText(aName);
-
- if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1) {
- myPoint1 = aSelectedObject;
- if (!myPoint1->_is_nil() && myPoint2->_is_nil())
- GroupPoints->PushButton3->click();
- }
- else if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 2) {
- myVector = aSelectedObject;
- if (!myVector->_is_nil() && !myObjects.length())
- GroupPoints->PushButton1->click();
- }
- else if (myEditCurrentArgument == GroupPoints->LineEdit3) {
- myPoint2 = aSelectedObject;
- if (!myPoint2->_is_nil() && !myObjects.length())
- GroupPoints->PushButton1->click();
+ else {
+ if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
+ if ( getConstructorId() == 1 ) myPoint1.nullify();
+ else myVector.nullify();
+ }
+ else if ( myEditCurrentArgument == GroupPoints->LineEdit3 ) {
+ myPoint2.nullify();
+ }
+ myEditCurrentArgument->setText("");
}
}
- // clear selection
- /* disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
- myGeomGUI->getApp()->selectionMgr()->clearSelected();
- connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
- this, SLOT(SelectionIntoArgument()));*/
- // here commented, because multiple objects can be selected IPAL 21437
-
displayPreview();
}
displayPreview();
}
-//=================================================================================
-// function : LineEditReturnPressed()
-// purpose :
-//=================================================================================
-void TransformationGUI_TranslationDlg::LineEditReturnPressed()
-{
- QLineEdit* send = (QLineEdit*)sender();
- if (send == GroupPoints->LineEdit1) {
- myEditCurrentArgument = send;
- GEOMBase_Skeleton::LineEditReturnPressed();
- }
-}
-
//=================================================================================
// function : ActivateThisDialog()
// purpose :
{
GEOMBase_Skeleton::ActivateThisDialog();
connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
- this, SLOT( SelectionIntoArgument() ) );
+ this, SLOT( SelectionIntoArgument() ) );
ConstructorsClicked( getConstructorId() );
}
//=================================================================================
bool TransformationGUI_TranslationDlg::isValid (QString& msg)
{
- int aConstructorId = getConstructorId();
-
- switch (aConstructorId) {
+ bool ok = false;
+ switch (getConstructorId()) {
case 0:
- {
- bool ok = true;
- ok = GroupPoints->SpinBox1->isValid( msg, !IsPreview() ) && ok;
- ok = GroupPoints->SpinBox2->isValid( msg, !IsPreview() ) && ok;
- ok = GroupPoints->SpinBox3->isValid( msg, !IsPreview() ) && ok;
- return myObjects.length() > 0 && ok;
- }
+ ok = GroupPoints->SpinBox1->isValid( msg, !IsPreview() ) &&
+ GroupPoints->SpinBox2->isValid( msg, !IsPreview() ) &&
+ GroupPoints->SpinBox3->isValid( msg, !IsPreview() ) &&
+ !myObjects.isEmpty();
+ break;
case 1:
- return myObjects.length() > 0 && !(myPoint1->_is_nil() || myPoint2->_is_nil());
+ ok = myPoint1 && myPoint2 && !myObjects.isEmpty();
+ break;
case 2:
- {
- bool ok = GroupPoints->SpinBox3->isValid( msg, !IsPreview() );
- return myObjects.length() > 0 && !(myVector->_is_nil()) && ok;
- }
+ ok = GroupPoints->SpinBox3->isValid( msg, !IsPreview() ) &&
+ myVector && !myObjects.isEmpty();
+ break;
default:
break;
}
- return false;
+ return ok;
}
//=================================================================================
aParameters<<GroupPoints->SpinBox3->text();
if (toCreateCopy) {
- for (int i = 0; i < myObjects.length(); i++) {
+ for (int i = 0; i < myObjects.count(); i++) {
myCurrObject = myObjects[i];
- anObj = anOper->TranslateDXDYDZCopy(myObjects[i], dx, dy, dz);
+ anObj = anOper->TranslateDXDYDZCopy(myObjects[i].get(), dx, dy, dz);
if (!anObj->_is_nil()) {
if(!IsPreview())
- anObj->SetParameters(aParameters.join(":").toLatin1().constData());
+ anObj->SetParameters(aParameters.join(":").toLatin1().constData());
objects.push_back(anObj._retn());
}
}
}
else {
- for (int i = 0; i < myObjects.length(); i++) {
+ for (int i = 0; i < myObjects.count(); i++) {
myCurrObject = myObjects[i];
- anObj = anOper->TranslateDXDYDZ(myObjects[i], dx, dy, dz);
+ anObj = anOper->TranslateDXDYDZ(myObjects[i].get(), dx, dy, dz);
if (!anObj->_is_nil()) {
if(!IsPreview()) {
- anObj->SetParameters(aParameters.join(":").toLatin1().constData());
- updateAttributes(anObj, aParameters);
- }
+ anObj->SetParameters(aParameters.join(":").toLatin1().constData());
+ updateAttributes(anObj, aParameters);
+ }
objects.push_back(anObj._retn());
- }
+ }
}
}
res = true;
case 1:
{
if (toCreateCopy) {
- for (int i = 0; i < myObjects.length(); i++) {
+ for (int i = 0; i < myObjects.count(); i++) {
myCurrObject = myObjects[i];
- anObj = anOper->TranslateTwoPointsCopy(myObjects[i], myPoint1, myPoint2);
+ anObj = anOper->TranslateTwoPointsCopy(myObjects[i].get(), myPoint1.get(), myPoint2.get());
if (!anObj->_is_nil())
objects.push_back(anObj._retn());
}
}
else {
- for (int i = 0; i < myObjects.length(); i++) {
+ for (int i = 0; i < myObjects.count(); i++) {
myCurrObject = myObjects[i];
- anObj = anOper->TranslateTwoPoints(myObjects[i], myPoint1, myPoint2);
+ anObj = anOper->TranslateTwoPoints(myObjects[i].get(), myPoint1.get(), myPoint2.get());
if (!anObj->_is_nil())
objects.push_back(anObj._retn());
}
QStringList aParameters;
aParameters<<GroupPoints->SpinBox3->text();
bool byDistance = GroupPoints->CheckBox1->isChecked();
+ createPathPreview( myVector.get() );
+
if (byDistance) {
double aDistance = GroupPoints->SpinBox3->value();
- for (int i = 0; i < myObjects.length(); i++) {
+ for (int i = 0; i < myObjects.count(); i++) {
myCurrObject = myObjects[i];
- anObj = anOper->TranslateVectorDistance(myObjects[i], myVector, aDistance, toCreateCopy);
+ anObj = anOper->TranslateVectorDistance(myObjects[i].get(), myVector.get(), aDistance, toCreateCopy);
if (!anObj->_is_nil()) {
- if(!IsPreview()) {
+ if(!IsPreview()) {
anObj->SetParameters(aParameters.join(":").toLatin1().constData());
- if (!toCreateCopy)
- updateAttributes(anObj, aParameters);
- }
+ if (!toCreateCopy)
+ updateAttributes(anObj, aParameters);
+ }
objects.push_back(anObj._retn());
}
}
}
else {
if (toCreateCopy) {
- for (int i = 0; i < myObjects.length(); i++) {
+ for (int i = 0; i < myObjects.count(); i++) {
myCurrObject = myObjects[i];
- anObj = anOper->TranslateVectorCopy(myObjects[i], myVector);
+ anObj = anOper->TranslateVectorCopy(myObjects[i].get(), myVector.get());
if (!anObj->_is_nil())
objects.push_back(anObj._retn());
}
}
else {
- for (int i = 0; i < myObjects.length(); i++) {
+ for (int i = 0; i < myObjects.count(); i++) {
myCurrObject = myObjects[i];
- anObj = anOper->TranslateVector(myObjects[i], myVector);
+ anObj = anOper->TranslateVector(myObjects[i].get(), myVector.get());
if (!anObj->_is_nil())
objects.push_back(anObj._retn());
}
// and we need to point the first argument directly
GEOM::ListOfGO_var anArgs = new GEOM::ListOfGO;
anArgs->length(1);
- anArgs[0] = myCurrObject;
+ anArgs[0] = myCurrObject.copy();
getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
/*theFindMethod=*/GEOM::FSM_Transformed,
- /*theInheritFirstArg=*/true);
+ /*theInheritFirstArg=*/true,
+ mainFrame()->CheckBoxAddPrefix->isChecked());
}
}
// function : CreateCopyModeChanged()
// purpose :
//=================================================================================
-void TransformationGUI_TranslationDlg::CreateCopyModeChanged (bool isCreateCopy)
+void TransformationGUI_TranslationDlg::CreateCopyModeChanged()
{
- mainFrame()->GroupBoxName->setEnabled(isCreateCopy);
+ mainFrame()->GroupBoxName->setEnabled(GroupPoints->CheckBox2->isChecked());
}
//=================================================================================
// function : ActivateDistanceChanged()
// purpose :
//=================================================================================
-void TransformationGUI_TranslationDlg::ActivateDistanceChanged (bool theEnable)
+void TransformationGUI_TranslationDlg::ActivateDistanceChanged()
{
- GroupPoints->SpinBox3->setEnabled(theEnable);
+ GroupPoints->SpinBox3->setEnabled( GroupPoints->CheckBox1->isChecked() );
displayPreview();
}
{
bool toCreateCopy = IsPreview() || GroupPoints->CheckBox2->isChecked();
if (toCreateCopy) {
- QMap<QString, GEOM::GEOM_Object_var> objMap;
-
switch (getConstructorId()) {
- case 0:
- return;
case 1:
- objMap[GroupPoints->LineEdit2->text()] = myPoint1;
- objMap[GroupPoints->LineEdit3->text()] = myPoint2;
+ GEOMBase::PublishSubObject( myPoint1.get() );
+ GEOMBase::PublishSubObject( myPoint2.get() );
break;
case 2:
- objMap[GroupPoints->LineEdit2->text()] = myVector;
+ GEOMBase::PublishSubObject( myVector.get() );
+ break;
+ default:
break;
}
- addSubshapesToFather(objMap);
+ }
+}
+
+//=================================================================================
+// function : createPathPreview
+// purpose :
+//=================================================================================
+void TransformationGUI_TranslationDlg::createPathPreview ( GEOM::GEOM_Object_ptr thePath )
+{
+ if ( IsPreview() ) {
+ TopoDS_Shape aShape;
+ GEOMBase::GetShape( thePath, aShape, TopAbs_SHAPE );
+ TopoDS_Edge anEdge = TopoDS::Edge( aShape );
+ ShapeAnalysis_Edge aShapeAnal;
+ TopoDS_Vertex aFirst = aShapeAnal.FirstVertex( anEdge );
+ TopoDS_Vertex aLast = aShapeAnal.LastVertex( anEdge );
+ TopoDS_Shape aVector = BRepBuilderAPI_MakeEdge(BRep_Tool::Pnt(aFirst), BRep_Tool::Pnt(aLast)).Shape();
+ const char* aName = "tmpVector";
+ Handle(GEOM_AISVector) anIO = new GEOM_AISVector( aVector, aName );
+
+ // add Prs to preview
+ SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
+ SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
+ if (aPrs)
+ aPrs->AddObject(anIO);
+ GEOMBase_Helper::displayPreview( aPrs, false, true );
}
}