X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPrimitiveGUI%2FPrimitiveGUI_BoxDlg.cxx;h=e68df444a1372b7408390ed668d5fbaa79c50fdf;hb=46574ac4f48a11f2161e754fe7c8df8684bc2b78;hp=ab47b76d39101dd0728d1667f4d7ce896713f1b0;hpb=392885c1a8d50369708bbe5e6b44033ed8b8ba51;p=modules%2Fgeom.git diff --git a/src/PrimitiveGUI/PrimitiveGUI_BoxDlg.cxx b/src/PrimitiveGUI/PrimitiveGUI_BoxDlg.cxx index ab47b76d3..e68df444a 100644 --- a/src/PrimitiveGUI/PrimitiveGUI_BoxDlg.cxx +++ b/src/PrimitiveGUI/PrimitiveGUI_BoxDlg.cxx @@ -1,4 +1,4 @@ -// 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 @@ -19,6 +19,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // GEOM GEOMGUI : GUI for Geometry component // File : PrimitiveGUI_BoxDlg.cxx // Author : Lucien PIGNOLONI, Open CASCADE S.A.S. @@ -42,7 +43,6 @@ #include #include -//#include //================================================================================= // class : PrimitiveGUI_BoxDlg() @@ -53,8 +53,7 @@ //================================================================================= PrimitiveGUI_BoxDlg::PrimitiveGUI_BoxDlg (GeometryGUI* theGeometryGUI, QWidget* parent, bool modal, Qt::WindowFlags fl) - : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl), - myInitial(true) + : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl) { QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BOX_2P"))); QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_BOX_DXYZ"))); @@ -113,9 +112,9 @@ void PrimitiveGUI_BoxDlg::Init() double step = resMgr->doubleValue("Geometry", "SettingsGeomStep", 100); // min, max, step and decimals for spin boxes - initSpinBox(GroupDimensions->SpinBox_DX, 0.000001, COORD_MAX, step, 6); // VSR: TODO: DBL_DIGITS_DISPLAY - initSpinBox(GroupDimensions->SpinBox_DY, 0.000001, COORD_MAX, step, 6); // VSR: TODO: DBL_DIGITS_DISPLAY - initSpinBox(GroupDimensions->SpinBox_DZ, 0.000001, COORD_MAX, step, 6); // VSR: TODO: DBL_DIGITS_DISPLAY + initSpinBox(GroupDimensions->SpinBox_DX, 0.000001, COORD_MAX, step, "length_precision" ); + initSpinBox(GroupDimensions->SpinBox_DY, 0.000001, COORD_MAX, step, "length_precision" ); + initSpinBox(GroupDimensions->SpinBox_DZ, 0.000001, COORD_MAX, step, "length_precision" ); // init variables GroupPoints->LineEdit1->setReadOnly(true); @@ -123,7 +122,8 @@ void PrimitiveGUI_BoxDlg::Init() GroupPoints->LineEdit1->setText(""); GroupPoints->LineEdit2->setText(""); - myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil(); + myPoint1.nullify(); + myPoint2.nullify(); double initValue = 200.0; GroupDimensions->SpinBox_DX->setValue(initValue); @@ -139,9 +139,6 @@ void PrimitiveGUI_BoxDlg::Init() 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(GroupDimensions->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); connect(GroupDimensions->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); connect(GroupDimensions->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox())); @@ -187,7 +184,7 @@ void PrimitiveGUI_BoxDlg::ConstructorsClicked (int constructorId) disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); globalSelection(); // close local contexts, if any - displayPreview(); + displayPreview(true); break; } } @@ -195,15 +192,9 @@ void PrimitiveGUI_BoxDlg::ConstructorsClicked (int constructorId) qApp->processEvents(); updateGeometry(); resize(minimumSizeHint()); + SelectionIntoArgument(); - if (myInitial) { - // on dialog initialization we init the first field with a selected object (if any) - SelectionIntoArgument(); - myInitial = false; - } - else { - displayPreview(); - } + displayPreview(true); } //================================================================================= @@ -248,72 +239,37 @@ void PrimitiveGUI_BoxDlg::SelectionIntoArgument() aSelMgr->selectedObjects(aSelList); if (aSelList.Extent() != 1) { - if (myEditCurrentArgument == GroupPoints->LineEdit1) myPoint1 = GEOM::GEOM_Object::_nil(); - else if (myEditCurrentArgument == GroupPoints->LineEdit2) myPoint2 = GEOM::GEOM_Object::_nil(); + if (myEditCurrentArgument == GroupPoints->LineEdit1) myPoint1.nullify(); + else if (myEditCurrentArgument == GroupPoints->LineEdit2) myPoint2.nullify(); 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; - - QString aName = GEOMBase::GetName(aSelectedObject); - - // Get Selected object if selected subshape + GEOM::GeomObjPtr aSelectedObject = getSelected( TopAbs_VERTEX ); TopoDS_Shape aShape; - if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull()) - { - TColStd_IndexedMapOfInteger aMap; - aSelMgr->GetIndexes(aSelList.First(), aMap); - if (aMap.Extent() == 1) // Local Selection - { - int anIndex = aMap(1); - aName.append(":vertex_" + QString::number(anIndex)); + if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) { + QString aName = GEOMBase::GetName( aSelectedObject.get() ); - //Find SubShape Object in Father - GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName); + myEditCurrentArgument->setText(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; // get Object from study - } + // clear selection + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + myGeomGUI->getApp()->selectionMgr()->clearSelected(); + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); + + if (myEditCurrentArgument == GroupPoints->LineEdit1) { + myPoint1 = aSelectedObject; + if (myPoint1 && !myPoint2) + GroupPoints->PushButton2->click(); } - else // Global Selection - { - if (aShape.ShapeType() != TopAbs_VERTEX) { - aSelectedObject = GEOM::GEOM_Object::_nil(); - aName = ""; - } + else if (myEditCurrentArgument == GroupPoints->LineEdit2) { + myPoint2 = aSelectedObject; + if (myPoint2 && !myPoint1) + GroupPoints->PushButton1->click(); } + } - - myEditCurrentArgument->setText(aName); - - // clear selection - disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); - myGeomGUI->getApp()->selectionMgr()->clearSelected(); - connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), - this, SLOT(SelectionIntoArgument())); - - if (myEditCurrentArgument == GroupPoints->LineEdit1) { - myPoint1 = aSelectedObject; - if (!myPoint1->_is_nil() && myPoint2->_is_nil()) - GroupPoints->PushButton2->click(); - } - else if (myEditCurrentArgument == GroupPoints->LineEdit2) { - myPoint2 = aSelectedObject; - if (!myPoint2->_is_nil() && myPoint1->_is_nil()) - GroupPoints->PushButton1->click(); - } - - displayPreview(); + displayPreview(true); } //================================================================================= @@ -330,10 +286,6 @@ void PrimitiveGUI_BoxDlg::SetEditCurrentArgument() // clear selection //disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); - //if (myInitial) - // myInitial = false; - //else - // myGeomGUI->getApp()->selectionMgr()->clearSelected(); if (send == GroupPoints->PushButton1) { myEditCurrentArgument = GroupPoints->LineEdit1; @@ -359,20 +311,7 @@ void PrimitiveGUI_BoxDlg::SetEditCurrentArgument() this, SLOT(SelectionIntoArgument())); // seems we need it only to avoid preview disappearing, caused by selection mode change - displayPreview(); -} - -//================================================================================= -// function : LineEditReturnPressed() -// purpose : -//================================================================================= -void PrimitiveGUI_BoxDlg::LineEditReturnPressed() -{ - QLineEdit* send = (QLineEdit*)sender(); - if (send == GroupPoints->LineEdit1 || send == GroupPoints->LineEdit2) { - myEditCurrentArgument = send; - GEOMBase_Skeleton::LineEditReturnPressed(); - } + displayPreview(true); } //================================================================================= @@ -387,7 +326,7 @@ void PrimitiveGUI_BoxDlg::ActivateThisDialog() connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())); } - displayPreview(); + displayPreview(true); } //================================================================================= @@ -406,7 +345,7 @@ void PrimitiveGUI_BoxDlg::enterEvent (QEvent*) //================================================================================= void PrimitiveGUI_BoxDlg::ValueChangedInSpinBox() { - displayPreview(); + displayPreview(true); } //================================================================================= @@ -424,18 +363,21 @@ GEOM::GEOM_IOperations_ptr PrimitiveGUI_BoxDlg::createOperation() //================================================================================= bool PrimitiveGUI_BoxDlg::isValid (QString& msg) { - bool ok = true; + bool ok = false; if( getConstructorId() == 1 ) { - ok = GroupDimensions->SpinBox_DX->isValid( msg, !IsPreview() ) && ok; - ok = GroupDimensions->SpinBox_DY->isValid( msg, !IsPreview() ) && ok; - ok = GroupDimensions->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok; - - ok = fabs( GroupDimensions->SpinBox_DX->value() ) > Precision::Confusion() && ok; - ok = fabs( GroupDimensions->SpinBox_DY->value() ) > Precision::Confusion() && ok; - ok = fabs( GroupDimensions->SpinBox_DZ->value() ) > Precision::Confusion() && ok; + ok = GroupDimensions->SpinBox_DX->isValid( msg, !IsPreview() ) && + GroupDimensions->SpinBox_DY->isValid( msg, !IsPreview() ) && + GroupDimensions->SpinBox_DZ->isValid( msg, !IsPreview() ) && + qAbs( GroupDimensions->SpinBox_DX->value() ) > Precision::Confusion() && + qAbs( GroupDimensions->SpinBox_DY->value() ) > Precision::Confusion() && + qAbs( GroupDimensions->SpinBox_DZ->value() ) > Precision::Confusion(); + } + else + { + ok = myPoint1 && myPoint2 && myPoint1 != myPoint2; } - return getConstructorId() == 0 ? !(myPoint1->_is_nil() || myPoint2->_is_nil()) : ok; + return ok; } //================================================================================= @@ -448,11 +390,13 @@ bool PrimitiveGUI_BoxDlg::execute (ObjectList& objects) GEOM::GEOM_Object_var anObj; + GEOM::GEOM_I3DPrimOperations_var anOper = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation()); + switch (getConstructorId()) { case 0: { - if (!CORBA::is_nil(myPoint1) && !CORBA::is_nil(myPoint2)) { - anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->MakeBoxTwoPnt(myPoint1, myPoint2); + if ( myPoint1 && myPoint2 ) { + anObj = anOper->MakeBoxTwoPnt(myPoint1.get(), myPoint2.get()); res = true; } } @@ -463,14 +407,14 @@ bool PrimitiveGUI_BoxDlg::execute (ObjectList& objects) double y = GroupDimensions->SpinBox_DY->value(); double z = GroupDimensions->SpinBox_DZ->value(); - anObj = GEOM::GEOM_I3DPrimOperations::_narrow(getOperation())->MakeBoxDXDYDZ(x, y, z); + anObj = anOper->MakeBoxDXDYDZ(x, y, z); if (!anObj->_is_nil() && !IsPreview()) { - QStringList aParameters; - aParameters << GroupDimensions->SpinBox_DX->text(); - aParameters << GroupDimensions->SpinBox_DY->text(); - aParameters << GroupDimensions->SpinBox_DZ->text(); - anObj->SetParameters(GeometryGUI::JoinObjectParameters(aParameters)); + QStringList aParameters; + aParameters << GroupDimensions->SpinBox_DX->text(); + aParameters << GroupDimensions->SpinBox_DY->text(); + aParameters << GroupDimensions->SpinBox_DZ->text(); + anObj->SetParameters(aParameters.join(":").toLatin1().constData()); } res = true; } @@ -490,9 +434,7 @@ bool PrimitiveGUI_BoxDlg::execute (ObjectList& objects) void PrimitiveGUI_BoxDlg::addSubshapesToStudy() { if (getConstructorId() == 0) { - QMap objMap; - objMap[GroupPoints->LineEdit1->text()] = myPoint1; - objMap[GroupPoints->LineEdit2->text()] = myPoint2; - addSubshapesToFather(objMap); + GEOMBase::PublishSubObject( myPoint1.get() ); + GEOMBase::PublishSubObject( myPoint2.get() ); } }