float * planeNormal = planeSource->GetNormal();
gp_Dir normal( planeNormal[0], planeNormal[1], planeNormal[2] );
- // find index of an axis most co-directed with plane normal
- int i, axId = 0;
+ // find a grid axis most co-directed with plane normal
+ // and cartesian axis most co-directed with plane normal
+ int i, maxAx = 0, gridAxId = 0;
+ gp_Dir dir, gridDir;
double maxDot = 0;
const vector<float> *curValues, *values = 0;
VISU::Result_i* result = myPrs3d->GetResult();
for ( i = 0; i < 3; ++i ) {
VISU::Result_i::TAxis axis = (VISU::Result_i::TAxis) i;
- gp_Dir dir;
curValues = result->GetAxisInfo(myPrs3d->GetMeshName(), axis, dir);
if ( curValues ) {
double dot = normal * dir;
if ( Abs( dot ) > Abs( maxDot )) {
maxDot = dot;
- axId = i;
+ gridDir = dir;
values = curValues;
+ gridAxId = i;
}
}
+ if ( Abs ( planeNormal[ maxAx ]) < Abs ( planeNormal[ i ]))
+ maxAx = i;
}
+ gp_XYZ axDir(0,0,0);
+ axDir.SetCoord( maxAx + 1, 1. );
+
// find index value
-// double v = SpinBoxDistance->value();
-// if ( reverse )
-// v = 1. - v;
-// for ( i = 0; i < values->size(); ++i )
-// if ( (*values)[ i ] > v )
-// break;
-// if ( i == values->size() ) --i;
-// cout << "maxDot: " << maxDot
-// << " axis: " << axId
-// << " index: " << i
-// << " planeNormal: " << planeNormal[0]<<" "<<planeNormal[1]<<" "<<planeNormal[2]
-// << endl;
-// if ( i != 0 && (*values)[ i ] - v > v - (*values)[ i - 1] ) {
-// --i;
-// cout << " Decrease index to " << i << endl;
-// }
+ double v = SpinBoxDistance->value();
+ // reverse value?
+ bool reverse = ( normal * axDir < 0 ); // normal and axis are opposite
+ if ( gridDir * axDir < 0 ) // grid dir and axis are opposite
+ reverse = !reverse;
+ if ( reverse )
+ v = 1. - v;
+ for ( i = 0; i < values->size(); ++i )
+ if ( (*values)[ i ] > v )
+ break;
+ if ( i == values->size() )
+ --i;
+ if ( i != 0 && (*values)[ i ] - v > v - (*values)[ i - 1] )
+ --i;
// set control values
myIsSelectPlane = true;
- CheckBoxIJKPlaneReverse->setChecked( false );
- SpinBoxIJKIndex->setValue( 0 );
- ButtonGroupIJKAxis->setButton( axId );
- onIJKAxisChanged( axId );
+ CheckBoxIJKPlaneReverse->setChecked( normal * axDir < 0 );
+ SpinBoxIJKIndex->setValue( i );
+ ButtonGroupIJKAxis->setButton( gridAxId );
+ onIJKAxisChanged( gridAxId ); // update label and range of index
myIsSelectPlane = false;
SetCurrentPlaneIJKParam();