bool modal, Qt::WindowFlags fl,
const double lineWidth )
: GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl ),
- myGeometryGUI( theGeometryGUI ),
- myLineWidth( lineWidth )
+ myMode( -1 ),
+ myOK( false ),
+ myLineWidth( lineWidth ),
+ myGeometryGUI( theGeometryGUI )
{
QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_UNDO" ) ) );
GroupType->RadioButton1->setText(tr("GEOM_SKETCHER_ABS"));
GroupType->RadioButton2->setText(tr("GEOM_SKETCHER_REL"));
GroupType->RadioButton3->close();
+ myTypeGroup = new QButtonGroup( this );
+ myTypeGroup->addButton( GroupType->RadioButton1, 0 );
+ myTypeGroup->addButton( GroupType->RadioButton2, 1 );
Group3Spin = new EntityGUI_3Spin( centralWidget() );
Group3Spin->GroupBox1->setTitle( tr( "GEOM_SKETCHER_VALUES" ) );
initSpinBox( Group3Spin->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
initSpinBox( Group3Spin->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR: TODO: DBL_DIGITS_DISPLAY
- /* signals and slots connections */
- connect( this, SIGNAL( constructorsClicked( int ) ), this, SLOT( PointClicked( int ) ) );
+ Group3Spin->SpinBox_DX->setValue(0.0);
+ Group3Spin->SpinBox_DY->setValue(0.0);
+ Group3Spin->SpinBox_DZ->setValue(0.0);
+ /* signals and slots connections */
connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
connect( Group3Spin->buttonUndo, SIGNAL( clicked() ), this, SLOT( ClickOnUndo() ) );
connect( Group3Spin->buttonRedo, SIGNAL( clicked() ), this, SLOT( ClickOnRedo() ) ) ;
- connect( GroupType->RadioButton1, SIGNAL( clicked() ), this, SLOT( TypeClicked() ) );
- connect( GroupType->RadioButton2, SIGNAL( clicked() ), this, SLOT( TypeClicked() ) );
+ connect( myTypeGroup, SIGNAL( buttonClicked( int ) ), this, SLOT( TypeClicked( int ) ) );
connect( Group3Spin->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
connect( Group3Spin->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
// function : TypeClicked()
// purpose : Radio button management
//=================================================================================
-void EntityGUI_3DSketcherDlg::TypeClicked()
+void EntityGUI_3DSketcherDlg::TypeClicked( int mode )
{
+ if ( mode == myMode ) return;
+
bool blocked = Group3Spin->SpinBox_DX->signalsBlocked();
Group3Spin->SpinBox_DX->blockSignals(true);
Group3Spin->SpinBox_DY->blockSignals(true);
Group3Spin->SpinBox_DZ->blockSignals(true);
// Get setting of step value from file configuration
- double x, y, z;
- GetLastPoints(x, y, z);
- if ( GroupType->RadioButton1->isChecked() ) { // XY
+ XYZ xyz = getLastPoint();
+ bool okx, oky, okz;
+ Group3Spin->SpinBox_DX->text().toDouble( &okx );
+ Group3Spin->SpinBox_DY->text().toDouble( &oky );
+ Group3Spin->SpinBox_DZ->text().toDouble( &okz );
+ if ( mode == 0 ) { // XY
Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_X2" ) );
Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_Y2" ) );
Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_Z2" ) );
- Group3Spin->SpinBox_DX->setValue( x + Group3Spin->SpinBox_DX->value() );
- Group3Spin->SpinBox_DY->setValue( y + Group3Spin->SpinBox_DY->value() );
- Group3Spin->SpinBox_DZ->setValue( z + Group3Spin->SpinBox_DZ->value() );
+ if ( okx ) Group3Spin->SpinBox_DX->setValue( xyz.x + Group3Spin->SpinBox_DX->value() );
+ if ( oky ) Group3Spin->SpinBox_DY->setValue( xyz.y + Group3Spin->SpinBox_DY->value() );
+ if ( okz ) Group3Spin->SpinBox_DZ->setValue( xyz.z + Group3Spin->SpinBox_DZ->value() );
Group3Spin->buttonApply->setFocus();
- } else if ( GroupType->RadioButton2->isChecked() ) { // DXDY
+ }
+ else { // DXDY
Group3Spin->TextLabel1->setText( tr( "GEOM_SKETCHER_DX2" ) );
Group3Spin->TextLabel2->setText( tr( "GEOM_SKETCHER_DY2" ) );
Group3Spin->TextLabel3->setText( tr( "GEOM_SKETCHER_DZ2" ) );
- Group3Spin->SpinBox_DX->setValue( Group3Spin->SpinBox_DX->value() - x );
- Group3Spin->SpinBox_DY->setValue( Group3Spin->SpinBox_DY->value() - y );
- Group3Spin->SpinBox_DZ->setValue( Group3Spin->SpinBox_DZ->value() - z );
+ if ( okx ) Group3Spin->SpinBox_DX->setValue( Group3Spin->SpinBox_DX->value() - xyz.x );
+ if ( oky ) Group3Spin->SpinBox_DY->setValue( Group3Spin->SpinBox_DY->value() - xyz.y );
+ if ( okz ) Group3Spin->SpinBox_DZ->setValue( Group3Spin->SpinBox_DZ->value() - xyz.z );
Group3Spin->buttonApply->setFocus();
}
Group3Spin->SpinBox_DX->blockSignals(blocked);
Group3Spin->SpinBox_DY->blockSignals(blocked);
Group3Spin->SpinBox_DZ->blockSignals(blocked);
+
+ myMode = mode;
}
//=================================================================================
//=================================================================================
void EntityGUI_3DSketcherDlg::ClickOnAddPoint()
{
- Locker lock( myOK );
-
- double x, y, z;
- GetCurrentPoints(x, y, z);
- myPointsList.append(x);
- myPointsList.append(y);
- myPointsList.append(z);
+ QString msg;
+ if ( !isValid( msg ) ) {
+ showError( msg );
+ return;
+ }
+ myPointsList.append( getCurrentPoint() );
myRedoList.clear();
- if ( GroupType->RadioButton2->isChecked() ) {
+ if ( myMode == 1 ) {
Group3Spin->SpinBox_DX->setValue( 0.0 );
Group3Spin->SpinBox_DY->setValue( 0.0 );
Group3Spin->SpinBox_DZ->setValue( 0.0 );
}
- GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
UpdateButtonsState();
+ GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
}
//=================================================================================
//=================================================================================
void EntityGUI_3DSketcherDlg::UpdateButtonsState()
{
- if ( !myPointsList.count() )
- GroupType->RadioButton1->setChecked( true );
- GroupType->RadioButton2->setEnabled( myPointsList.count() > 2 );
- Group3Spin->buttonUndo->setEnabled( myPointsList.count() > 2 );
- Group3Spin->buttonRedo->setEnabled( myRedoList.count() > 2 );
+ if ( myPointsList.count() == 0 ) GroupType->RadioButton1->click();
+ GroupType->RadioButton2->setEnabled( myPointsList.count() > 0 );
+ Group3Spin->buttonUndo->setEnabled( myPointsList.count() > 0 );
+ Group3Spin->buttonRedo->setEnabled( myRedoList.count() > 0 );
}
//=================================================================================
//=================================================================================
void EntityGUI_3DSketcherDlg::ClickOnUndo()
{
- if (myPointsList.count() > 2) {
- double x, y, z;
- GetLastPoints(x, y, z);
- myRedoList.append(x);
- myRedoList.append(y);
- myRedoList.append(z);
- myPointsList.removeLast();
- myPointsList.removeLast();
- myPointsList.removeLast();
-
+ if (myPointsList.count() > 0) {
+ myRedoList.append( myPointsList.takeLast() );
UpdateButtonsState();
GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
}
//=================================================================================
void EntityGUI_3DSketcherDlg::ClickOnRedo()
{
- int count = myRedoList.count();
- if ( count > 2 ) {
- myPointsList.append( myRedoList[count-3] );
- myPointsList.append( myRedoList[count-2] );
- myPointsList.append( myRedoList[count-1] );
- myRedoList.removeLast();
- myRedoList.removeLast();
- myRedoList.removeLast();
-
+ if ( myRedoList.count() > 0) {
+ myPointsList.append( myRedoList.takeLast() );
UpdateButtonsState();
GEOMBase_Helper::displayPreview( false, true, true, myLineWidth );
}
Group3Spin->SpinBox_DY->setValue( aY );
Group3Spin->SpinBox_DZ->setValue( aZ );
} else if ( GroupType->RadioButton2->isChecked() ) {
- double x, y, z;
- GetLastPoints(x, y, z);
- Group3Spin->SpinBox_DX->setValue( aX - x );
- Group3Spin->SpinBox_DY->setValue( aY - y );
- Group3Spin->SpinBox_DZ->setValue( aZ - z );
+ XYZ xyz = getLastPoint();
+ Group3Spin->SpinBox_DX->setValue( aX - xyz.x );
+ Group3Spin->SpinBox_DY->setValue( aY - xyz.y );
+ Group3Spin->SpinBox_DZ->setValue( aZ - xyz.z );
}
Group3Spin->SpinBox_DX->blockSignals(blocked);
Group3Spin->SpinBox_DY->blockSignals(blocked);
//=================================================================================
bool EntityGUI_3DSketcherDlg::isValid( QString& msg )
{
- return true;
+ bool ok = true;
+ ok = Group3Spin->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
+ ok = Group3Spin->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
+ ok = Group3Spin->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
+ return ok;
}
//=================================================================================
{
GEOM::ListOfDouble_var aCoordsArray = new GEOM::ListOfDouble;
if (!myOK || myPointsList.size() == 0)
- aCoordsArray->length(myPointsList.size()+3);
+ aCoordsArray->length((myPointsList.size()+1)*3);
else
- aCoordsArray->length(myPointsList.size());
+ aCoordsArray->length(myPointsList.size()*3);
+
+ QStringList aParameters;
int i = 0;
- QList<double>::const_iterator it;
+ QList<XYZ>::const_iterator it;
for(it = myPointsList.begin(); it != myPointsList.end(); ++it ) {
- aCoordsArray[i] = *it;
- i++;
+ aCoordsArray[i++] = (*it).x;
+ aCoordsArray[i++] = (*it).y;
+ aCoordsArray[i++] = (*it).z;
+ aParameters << (*it).xt;
+ aParameters << (*it).yt;
+ aParameters << (*it).zt;
}
if (!myOK || myPointsList.size() == 0) {
- double x, y, z;
- GetCurrentPoints(x, y, z);
- aCoordsArray[i] = x;
- aCoordsArray[i+1] = y;
- aCoordsArray[i+2] = z;
+ XYZ xyz = getCurrentPoint();
+ aCoordsArray[i++] = xyz.x;
+ aCoordsArray[i++] = xyz.y;
+ aCoordsArray[i++] = xyz.z;
+ aParameters << xyz.xt;
+ aParameters << xyz.yt;
+ aParameters << xyz.zt;
}
GEOM::GEOM_ICurvesOperations_var anOper = GEOM::GEOM_ICurvesOperations::_narrow(getOperation());
GEOM::GEOM_Object_var anObj = anOper->Make3DSketcher( aCoordsArray );
- if ( !anObj->_is_nil() )
+ if ( !anObj->_is_nil() ) {
+ if ( !IsPreview() ) anObj->SetParameters(aParameters.join(":").toLatin1().constData());
objects.push_back( anObj._retn() );
+ }
return true;
}
//=================================================================================
void EntityGUI_3DSketcherDlg::initSpinBox( QDoubleSpinBox* spinBox,
- double min, double max,
- double step, int decimals )
+ double min, double max,
+ double step, int decimals )
{
spinBox->setDecimals( decimals );
spinBox->setRange( min, max );
//=================================================================================
bool EntityGUI_3DSketcherDlg::ClickOnApply()
{
- if (myPointsList.count() > 3) {
- myPointsList.append(myPointsList[0]);
- myPointsList.append(myPointsList[1]);
- myPointsList.append(myPointsList[2]);
+ QString msg;
+ if ( !isValid( msg ) ) {
+ showError( msg );
+ return false;
}
+ if (myPointsList.count() > 0)
+ myPointsList.append(myPointsList[0]);
+
Locker lock( myOK );
if ( !onAccept() )
}
//=================================================================================
-// function : GetLastPoints()
+// function : getLastPoint()
// purpose : return last points from list
//=================================================================================
-void EntityGUI_3DSketcherDlg::GetLastPoints(double& x, double& y, double& z)
+EntityGUI_3DSketcherDlg::XYZ EntityGUI_3DSketcherDlg::getLastPoint() const
{
- int count = myPointsList.count();
- x = count > 2 ? myPointsList[count-3] : 0.0;
- y = count > 2 ? myPointsList[count-2] : 0.0;
- z = count > 2 ? myPointsList[count-1] : 0.0;
+ return myPointsList.count() > 0 ? myPointsList.last() : XYZ();
}
//=================================================================================
-// function : GetCurrentPoints()
+// function : getCurrentPoint()
// purpose : returns current points
//=================================================================================
-void EntityGUI_3DSketcherDlg::GetCurrentPoints(double& x, double& y, double& z)
+EntityGUI_3DSketcherDlg::XYZ EntityGUI_3DSketcherDlg::getCurrentPoint() const
{
- if ( GroupType->RadioButton1->isChecked() ) {
- x = Group3Spin->SpinBox_DX->value();
- y = Group3Spin->SpinBox_DY->value();
- z = Group3Spin->SpinBox_DZ->value();
- } else { // if (GroupType->RadioButton2->isChecked())
- GetLastPoints(x, y, z);
- x += Group3Spin->SpinBox_DX->value();
- y += Group3Spin->SpinBox_DY->value();
- z += Group3Spin->SpinBox_DZ->value();
+ XYZ xyz;
+ if ( myMode == 0 ) {
+ xyz.x = Group3Spin->SpinBox_DX->value();
+ xyz.y = Group3Spin->SpinBox_DY->value();
+ xyz.z = Group3Spin->SpinBox_DZ->value();
+ }
+ else {
+ xyz = getLastPoint();
+ xyz.x += Group3Spin->SpinBox_DX->value();
+ xyz.y += Group3Spin->SpinBox_DY->value();
+ xyz.z += Group3Spin->SpinBox_DZ->value();
}
+ xyz.xt = Group3Spin->SpinBox_DX->text();
+ xyz.yt = Group3Spin->SpinBox_DY->text();
+ xyz.zt = Group3Spin->SpinBox_DZ->text();
+ return xyz;
}
//================================================================
CORBA::String_var objStr = myGeometryGUI->getApp()->orb()->object_to_string( object );
getDisplayer()->SetName( objStr.in() );
- // Create wire from applayed object
+ // Create wire from applied object
TopoDS_Shape anApplyedWire, aLastSegment;
if ( !createShapes( object, anApplyedWire, aLastSegment ) )
return;
aShape.ShapeType() != TopAbs_WIRE && aShape.ShapeType() != TopAbs_VERTEX )
return false;
- if ( myOK ) {
- theApplyedWire = aShape;
+ theApplyedWire = aShape;
+ if ( myOK )
return true;
- }
BRepBuilderAPI_MakeWire aBuilder;
- TopExp_Explorer anExp( aShape, TopAbs_EDGE );
+ TopExp_Explorer edgeExp( aShape, TopAbs_EDGE );
while ( 1 ) {
- TopoDS_Shape anEdge = anExp.Current();
- anExp.Next();
- if ( anExp.More() ) // i.e. non-last edge
+ TopoDS_Shape anEdge = edgeExp.Current();
+ edgeExp.Next();
+ if ( edgeExp.More() ) // i.e. non-last edge
aBuilder.Add( TopoDS::Edge( anEdge ) );
else {
theLastSegment = anEdge;
}
}
- if ( aBuilder.IsDone() )
+ if ( aBuilder.IsDone() ) {
theApplyedWire = aBuilder.Shape();
+ }
+ else if ( !theLastSegment.IsNull() ) {
+ TopExp_Explorer vertexExp( theLastSegment, TopAbs_VERTEX );
+ theApplyedWire = vertexExp.Current();
+ }
return true;
}