+ erasePreview();
+
+ const int id = getConstructorId();
+
+ if ( id == 0 ) { // by planar face selection
+ if ( CORBA::is_nil( myFace ) ) {
+ if ( !showPreview )
+ showError( "Face has to be selected" );
+ return false;
+ }
+
+ // PAL12781: set center of WPL to face's center of mass
+ // like it is done for LCS creation
+ CORBA::Double Ox, Oy, Oz, Zx, Zy, Zz, Xx, Xy, Xz;
+ Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
+ Zz = Xx = 1.;
+
+ GEOM::GEOM_IMeasureOperations_ptr aMeasureOp =
+ myGeomGUI->GetGeomGen()->GetIMeasureOperations();
+ aMeasureOp->GetPosition( myFace, Ox, Oy, Oz, Zx, Zy, Zz, Xx, Xy, Xz);
+
+ if ( aMeasureOp->IsDone() ) {
+ gp_Pnt aPnt ( Ox, Oy, Oz );
+ gp_Dir aDirN ( Zx, Zy, Zz );
+ gp_Dir aDirX ( Xx, Xy, Xz );
+ myWPlane = gp_Ax3( aPnt, aDirN, aDirX );
+ }
+ else {
+ if ( !showPreview )
+ showError( "Wrong shape selected (has to be a planar face)" );
+ return false;
+ }
+ }
+ else if ( id == 1 ) { // by two vectors (Ox & Oz)
+ if ( CORBA::is_nil( myVectX ) || CORBA::is_nil( myVectZ ) ) {
+ if ( !showPreview )
+ showError( "Two vectors have to be selected" );
+ return false;
+ }
+
+ TopoDS_Edge aVectX, aVectZ;
+ TopoDS_Vertex VX1, VX2, VZ1, VZ2;
+ gp_Vec aVX, aVZ;
+
+ if ( !GEOMBase::GetShape( myVectX, aVectX, TopAbs_EDGE ) ||
+ !GEOMBase::GetShape( myVectZ, aVectZ, TopAbs_EDGE ) ) {
+ if ( !showPreview )
+ showError( "Wrong shape selected (two vectors(edges) have to be selected)" );
+ return false;
+ }
+
+ TopExp::Vertices( aVectX, VX1, VX2, Standard_True );
+ TopExp::Vertices( aVectZ, VZ1, VZ2, Standard_True );
+
+ if ( VX1.IsNull() || VX2.IsNull() ) {
+ if ( !showPreview )
+ showError( "Bad OX vector" );
+ return false;
+ }
+ if ( VZ1.IsNull() || VZ2.IsNull() ) {
+ if ( !showPreview )
+ showError( "Bad OZ vector" );
+ return false;
+ }
+
+ aVX = gp_Vec( BRep_Tool::Pnt( VX1 ), BRep_Tool::Pnt( VX2 ) );
+ aVZ = gp_Vec( BRep_Tool::Pnt( VZ1 ), BRep_Tool::Pnt( VZ2 ) );
+
+ if ( aVX.Magnitude() < Precision::Confusion() ) {
+ if ( !showPreview )
+ showError( "Bad OX vector" );
+ return false;
+ }
+ if ( aVZ.Magnitude() < Precision::Confusion() ) {
+ if ( !showPreview )
+ showError( "Bad OZ vector" );
+ return false;
+ }
+
+ gp_Dir aDirX = gp_Dir( aVX.X(), aVX.Y(), aVX.Z() );
+ gp_Dir aDirZ = gp_Dir( aVZ.X(), aVZ.Y(), aVZ.Z() );
+
+ if ( aDirX.IsParallel( aDirZ, Precision::Angular() ) ) {
+ if ( !showPreview )
+ showError( "Parallel vectors selected" );
+ return false;
+ }
+
+ myWPlane = gp_Ax3( BRep_Tool::Pnt( VX1 ), aDirZ, aDirX );
+
+ }
+ else if ( id == 2 ) { // by selection from standard (OXY or OYZ, or OZX)
+ gp_Ax2 anAx2;
+
+ if ( aOriginType == 1 ) anAx2 = gp::XOY();
+ else if ( aOriginType == 2 ) anAx2 = gp::YOZ();
+ else if ( aOriginType == 0 ) anAx2 = gp::ZOX();
+
+ myWPlane = gp_Ax3( anAx2 );
+
+ }
+ else {
+ return false;
+ }
+
+ if ( myReverseCB->isChecked() ) {
+ myWPlane.YReverse();
+ myWPlane.ZReverse();
+ }
+
+ if ( showPreview ) {
+ GEOM::GEOM_IBasicOperations_var aBasicOp = getGeomEngine()->GetIBasicOperations();
+ GEOM::GEOM_Object_var anObj = aBasicOp->MakeMarker
+ ( myWPlane.Location().X(), myWPlane.Location().Y(), myWPlane.Location().Z(),
+ myWPlane.XDirection().X(), myWPlane.XDirection().Y(), myWPlane.XDirection().Z(),
+ myWPlane.YDirection().X(), myWPlane.YDirection().Y(), myWPlane.YDirection().Z() );
+ displayPreview( anObj );
+ }
+
+ return true;