Code refactoring and small modifications

This commit is contained in:
rnc 2012-08-02 15:29:22 +00:00
parent 35a548b486
commit 51a17b950d
2 changed files with 82 additions and 63 deletions

View File

@ -335,6 +335,8 @@ void EntityGUI_3DSketcherDlg::TypeClicked( int mode )
updateGeometry(); updateGeometry();
resize(minimumSizeHint()); resize(minimumSizeHint());
GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
} }
//================================================================================= //=================================================================================
@ -354,17 +356,20 @@ void EntityGUI_3DSketcherDlg::ClickOnAddPoint()
((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myAnglePrs, true); ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myAnglePrs, true);
((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true); ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true);
// Store last angle dimensions if any // Store last angle dimensions if needed
if(GroupType->RadioButton3->isChecked() && GroupAngles->SpinBox_DL->value()>Precision::Confusion()) if( GroupType->RadioButton3->isChecked() )
{ {
double anAngle2 = 0.0; double anAngle2 = 0.0;
if (GroupAngles->checkBox->isChecked()) if (GroupAngles->checkBox->isChecked())
anAngle2 = GroupAngles->SpinBox_DA2->value(); anAngle2 = GroupAngles->SpinBox_DA2->value();
// Store length dimensions
displayLength(GroupAngles->SpinBox_DL->value(), true);
// Store angle dimensions
displayAngle(GroupAngles->SpinBox_DA->value(), anAngle2, GroupAngles->SpinBox_DL->value(), myOrientation, true); displayAngle(GroupAngles->SpinBox_DA->value(), anAngle2, GroupAngles->SpinBox_DL->value(), myOrientation, true);
} }
// Store last length dimensions if any // Store last length dimensions if needed
if (GroupType->RadioButton1->isChecked() || if (GroupType->RadioButton1->isChecked() ||
GroupType->RadioButton2->isChecked()) GroupType->RadioButton2->isChecked())
{ {
@ -390,6 +395,12 @@ void EntityGUI_3DSketcherDlg::ClickOnAddPoint()
Group3Spin->SpinBox_DY->setValue( 0.0 ); Group3Spin->SpinBox_DY->setValue( 0.0 );
Group3Spin->SpinBox_DZ->setValue( 0.0 ); Group3Spin->SpinBox_DZ->setValue( 0.0 );
} }
else if ( myMode == 2 )
{
GroupAngles->SpinBox_DA->setValue( 0.0 );
GroupAngles->SpinBox_DL->setValue( 0.0 );
GroupAngles->SpinBox_DA2->setValue( 0.0 );
}
UpdateButtonsState(); UpdateButtonsState();
GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth ); GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
@ -431,23 +442,17 @@ void EntityGUI_3DSketcherDlg::ClickOnUndo()
if (myPrsTypeList.back() != NONE) if (myPrsTypeList.back() != NONE)
{ {
// Remove last prepended IO // Remove last prepended IO
myLengthPrs->GetObjects(anIOList); removeLastIOFromPrs( TYPE_LENGTH );
myLengthIORedoList.Prepend(anIOList.First()); // due to AIS_ListOfInteractive structure
// we have to prepend objects and take first then
myLengthPrs->RemoveFirst();
} }
if ( myPrsTypeList.back() == TYPE_ANGLE || if ( myPrsTypeList.back() == TYPE_ANGLE ||
myPrsTypeList.back() == TYPE_TWO_ANGLES ) myPrsTypeList.back() == TYPE_TWO_ANGLES )
{ {
myAnglePrs->GetObjects(anIOList); // Remove first Angle IO from presentation
myAngleIORedoList.Prepend(anIOList.First()); removeLastIOFromPrs( TYPE_ANGLE );
myAnglePrs->RemoveFirst();
if ( myPrsTypeList.back() == TYPE_TWO_ANGLES ) if ( myPrsTypeList.back() == TYPE_TWO_ANGLES )
{ {
// Remove a second IO // Remove second Angle IO
myAnglePrs->GetObjects(anIOList); removeLastIOFromPrs( TYPE_ANGLE );
myAngleIORedoList.Prepend(anIOList.First());
myAnglePrs->RemoveFirst();
} }
} }
@ -461,7 +466,7 @@ void EntityGUI_3DSketcherDlg::ClickOnUndo()
if (isAngleVisible) if (isAngleVisible)
((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs); ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs);
ValueChangedInSpinBox(0.0); // To update preview updateViewer();
} }
} }
@ -481,23 +486,20 @@ void EntityGUI_3DSketcherDlg::ClickOnRedo()
((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true); ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true);
if ( myPrsTypeRedoList.back() != NONE ) if ( myPrsTypeRedoList.back() != NONE )
{ restoreLastIOToPrs( TYPE_LENGTH );
myLengthPrs->PrependObject(myLengthIORedoList.First());
myLengthIORedoList.RemoveFirst();
}
if ( myPrsTypeRedoList.back() == TYPE_ANGLE || if ( myPrsTypeRedoList.back() == TYPE_ANGLE ||
myPrsTypeRedoList.back() == TYPE_TWO_ANGLES ) myPrsTypeRedoList.back() == TYPE_TWO_ANGLES )
{ {
myAnglePrs->PrependObject(myAngleIORedoList.First()); // Add a first IO from the Redo list
myAngleIORedoList.RemoveFirst(); restoreLastIOToPrs( TYPE_ANGLE );
if ( myPrsTypeRedoList.back() == TYPE_TWO_ANGLES ) if ( myPrsTypeRedoList.back() == TYPE_TWO_ANGLES )
{ {
// Add a second IO from the Redo list // Add a second IO from the Redo list
myAnglePrs->PrependObject(myAngleIORedoList.First()); restoreLastIOToPrs( TYPE_ANGLE );
myAngleIORedoList.RemoveFirst();
} }
} }
// Record last prs type // Record last prs type
myPrsTypeList.push_back(myPrsTypeRedoList.back()); myPrsTypeList.push_back(myPrsTypeRedoList.back());
myPrsTypeRedoList.pop_back(); myPrsTypeRedoList.pop_back();
@ -508,10 +510,50 @@ void EntityGUI_3DSketcherDlg::ClickOnRedo()
if (isAngleVisible) if (isAngleVisible)
((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs); ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Display(myAnglePrs);
ValueChangedInSpinBox(0.0); // To update preview updateViewer();
} }
} }
//=================================================================================
// function : removeLastIO()
// purpose :
//=================================================================================
void EntityGUI_3DSketcherDlg::removeLastIOFromPrs(int type)
{
AIS_ListOfInteractive anIOList;
if (type == TYPE_LENGTH)
{
myLengthPrs->GetObjects(anIOList);
myLengthIORedoList.Prepend(anIOList.First()); // Store last prepended Length IO in redo list
myLengthPrs->RemoveFirst(); // Remove it from myLengthPrs
}
if (type == TYPE_ANGLE)
{
myAnglePrs->GetObjects(anIOList);
myAngleIORedoList.Prepend(anIOList.First()); // Store last prepended Angle IO in redo list
myAnglePrs->RemoveFirst(); // Remove it from myAnglePrs
}
}
//=================================================================================
// function : restoreLastIO()
// purpose :
//=================================================================================
void EntityGUI_3DSketcherDlg::restoreLastIOToPrs(int type)
{
if (type == TYPE_LENGTH)
{
myLengthPrs->PrependObject(myLengthIORedoList.First()); // Restore last removed IO
myLengthIORedoList.RemoveFirst(); // Remove it from redo list
}
if (type == TYPE_ANGLE)
{
myAnglePrs->PrependObject(myAngleIORedoList.First()); // Restore last removed IO
myAngleIORedoList.RemoveFirst(); // Remove it from redo list
}
}
//================================================================================= //=================================================================================
// function : SelectionIntoArgument() // function : SelectionIntoArgument()
// purpose : Called when selection as changed // purpose : Called when selection as changed
@ -611,7 +653,7 @@ void EntityGUI_3DSketcherDlg::ValueChangedInSpinBox( double newValue )
{ {
GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth ); GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
if(GroupType->RadioButton3->isChecked() && GroupAngles->SpinBox_DL->value()>Precision::Confusion()) if(GroupType->RadioButton3->isChecked())
{ {
double anAngle2 = 0.0; double anAngle2 = 0.0;
if (GroupAngles->checkBox->isChecked()) if (GroupAngles->checkBox->isChecked())
@ -622,9 +664,7 @@ void EntityGUI_3DSketcherDlg::ValueChangedInSpinBox( double newValue )
} }
if( GroupType->RadioButton1->isChecked() || if( GroupType->RadioButton1->isChecked() ||
GroupType->RadioButton2->isChecked() ) GroupType->RadioButton2->isChecked() )
{ displayLength();
displayLength();
}
} }
@ -638,20 +678,8 @@ void EntityGUI_3DSketcherDlg::BoxChecked( bool checked )
SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow(); SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
if (send == GroupAngles->checkBox) if (send == GroupAngles->checkBox)
{
GroupAngles->SpinBox_DA2->setEnabled(checked); GroupAngles->SpinBox_DA2->setEnabled(checked);
GEOMBase_Helper::displayPreview( true, false, true, true, myLineWidth );
if(GroupAngles->SpinBox_DL->value()>Precision::Confusion())
{
double anAngle2 = 0.0;
if (checked)
anAngle2 = GroupAngles->SpinBox_DA2->value();
displayAngle(GroupAngles->SpinBox_DA->value(), anAngle2, GroupAngles->SpinBox_DL->value(), myOrientation);
displayLength(GroupAngles->SpinBox_DL->value());
}
}
else if (send == GroupControls->CheckBox1) else if (send == GroupControls->CheckBox1)
{ {
((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true); ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->Erase(myLengthPrs, true);
@ -673,8 +701,8 @@ void EntityGUI_3DSketcherDlg::BoxChecked( bool checked )
else else
isAngleVisible=false; isAngleVisible=false;
} }
updateViewer(); // updateViewer();
ValueChangedInSpinBox(0.0); ValueChangedInSpinBox(0.0); // To redisplay the previews
} }
//================================================================================= //=================================================================================
@ -959,12 +987,10 @@ void EntityGUI_3DSketcherDlg::displayPreview( GEOM::GEOM_Object_ptr object,
GEOMBase_Helper::displayPreview( aPrs, append, update ); GEOMBase_Helper::displayPreview( aPrs, append, update );
getDisplayer()->SetColor( line_color ); getDisplayer()->SetColor( line_color );
// Display trihedron // Display local trihedron if the mode is relatives coordinates or angles
// if(GroupType->RadioButton3->isChecked()) if (myMode == 1 || myMode == 2)
// displayTrihedron(3); displayTrihedron(2);
// else
displayTrihedron(2);
getDisplayer()->UnsetName(); getDisplayer()->UnsetName();
@ -992,7 +1018,6 @@ void EntityGUI_3DSketcherDlg::displayTrihedron(int selMode)
{ {
aSPrs->PrependObject(anIO); aSPrs->PrependObject(anIO);
GEOMBase_Helper::displayPreview( aSPrs, true, true ); GEOMBase_Helper::displayPreview( aSPrs, true, true );
// ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->LocalSelection(aSPrs, selMode);
} }
} }
@ -1002,11 +1027,9 @@ void EntityGUI_3DSketcherDlg::displayTrihedron(int selMode)
//================================================================ //================================================================
void EntityGUI_3DSketcherDlg::displayAngle(double theAngle1, double theAngle2, double theLength, int theOrientation, bool store) void EntityGUI_3DSketcherDlg::displayAngle(double theAngle1, double theAngle2, double theLength, int theOrientation, bool store)
{ {
if(Abs(theAngle2 - 90.0) < Precision::Angular()) if( Abs(theAngle2 - 90.0) < Precision::Angular() ||
theLength < Precision::Confusion() )
return; return;
// Display length dimensions
displayLength(theLength, store);
SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow(); SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
@ -1015,7 +1038,7 @@ void EntityGUI_3DSketcherDlg::displayAngle(double theAngle1, double theAngle2, d
gp_Pnt Last_Pnt(Last.x,Last.y,Last.z); gp_Pnt Last_Pnt(Last.x,Last.y,Last.z);
gp_Pnt Current_Pnt(Current.x,Current.y,Current.z); gp_Pnt Current_Pnt(Current.x,Current.y,Current.z);
gp_Pnt P1, P2; //, P3; gp_Pnt P1, P2;
bool twoAngles = GroupAngles->checkBox->isChecked(); bool twoAngles = GroupAngles->checkBox->isChecked();
@ -1027,7 +1050,6 @@ void EntityGUI_3DSketcherDlg::displayAngle(double theAngle1, double theAngle2, d
P2 = gp_Pnt(Last.x + theLength * cos(theAngle1 * M_PI / 180.), P2 = gp_Pnt(Last.x + theLength * cos(theAngle1 * M_PI / 180.),
Last.y + theLength * sin(theAngle1 * M_PI / 180.), Last.y + theLength * sin(theAngle1 * M_PI / 180.),
Last.z); Last.z);
// P3 = gp_Pnt(Last.x,Last.y,theLength); // Z direction (normal to the plane)
break; break;
} }
case 2: //OYZ case 2: //OYZ
@ -1036,8 +1058,6 @@ void EntityGUI_3DSketcherDlg::displayAngle(double theAngle1, double theAngle2, d
P2 = gp_Pnt(Last.x, P2 = gp_Pnt(Last.x,
Last.y + theLength * cos(theAngle1 * M_PI / 180.), Last.y + theLength * cos(theAngle1 * M_PI / 180.),
Last.z + theLength * sin(theAngle1 * M_PI / 180.)); Last.z + theLength * sin(theAngle1 * M_PI / 180.));
// P2 = gp_Pnt(Last.x,Current.y,Current.z); // Projection in OYZ plane
// P3 = gp_Pnt(theLength,Last.y,Last.z); // X direction
break; break;
} }
case 3: //OXZ case 3: //OXZ
@ -1046,8 +1066,6 @@ void EntityGUI_3DSketcherDlg::displayAngle(double theAngle1, double theAngle2, d
P2 = gp_Pnt( Last.x + theLength * cos(theAngle1 * M_PI / 180.) , P2 = gp_Pnt( Last.x + theLength * cos(theAngle1 * M_PI / 180.) ,
Last.y, Last.y,
Last.z + theLength * sin(theAngle1 * M_PI / 180.)); Last.z + theLength * sin(theAngle1 * M_PI / 180.));
// P2 = gp_Pnt(Current.x,Last.y,Current.z); // Projection in OXZ plane
// P3 = gp_Pnt(Last.x,theLength,Last.z); // Y direction
break; break;
} }
} }
@ -1077,8 +1095,6 @@ void EntityGUI_3DSketcherDlg::displayAngle(double theAngle1, double theAngle2, d
Handle(Prs3d_AngleAspect) asp = new Prs3d_AngleAspect(); Handle(Prs3d_AngleAspect) asp = new Prs3d_AngleAspect();
asp->LineAspect()->SetWidth(w); asp->LineAspect()->SetWidth(w);
anAngleIO->Attributes()->SetAngleAspect(asp); anAngleIO->Attributes()->SetAngleAspect(asp);
//TEST
//anAngleIO->SetSelectionMode(1);
SOCC_Prs* aSPrs = dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0)); SOCC_Prs* aSPrs = dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
@ -1134,7 +1150,7 @@ void EntityGUI_3DSketcherDlg::displayLength(double theLength, bool store)
double aLength = 0.0; double aLength = 0.0;
if( theLength < 0) if( theLength < 0) // Calculate length if not given
{ {
aLength = sqrt((Last.x - Current.x)*(Last.x - Current.x) + aLength = sqrt((Last.x - Current.x)*(Last.x - Current.x) +
(Last.y - Current.y)*(Last.y - Current.y) + (Last.y - Current.y)*(Last.y - Current.y) +

View File

@ -96,6 +96,9 @@ private:
XYZ getCurrentPoint() const; XYZ getCurrentPoint() const;
std::string doubleToString( double ); std::string doubleToString( double );
void removeLastIOFromPrs( int );
void restoreLastIOToPrs( int );
private: private:
XYZList myPointsList; XYZList myPointsList;