+//================================================================================
+/*!
+ * \brief Set shape of an arrow of a unit length and nb of arrows
+ */
+//================================================================================
+
+void SMESHGUI_MeshEditPreview::SetArrowShapeAndNb( int nbArrows,
+ double headLength,
+ double headRadius,
+ double start,
+ const char* labels)
+{
+ const int theNbPoints = 10; // in one arrow
+ myUnitArrowPnts.reserve( theNbPoints );
+ myUnitArrowPnts.clear();
+
+ // unit arrow || OZ
+
+ for ( int i = 0; i < theNbPoints - 2; ++i )
+ {
+ double angle = i * 2 * M_PI / ( theNbPoints - 2 );
+ myUnitArrowPnts.push_back( gp_Pnt( headRadius * Cos( angle ),
+ headRadius * Sin( angle ),
+ 1. - headLength ));
+ }
+ myUnitArrowPnts.push_back( gp_Pnt( 0, 0, start ));
+ myUnitArrowPnts.push_back( gp_Pnt( 0, 0, 1 ));
+
+
+ // nodes of all arrows
+
+ vtkPoints* aPoints = vtkPoints::New();
+ aPoints->SetNumberOfPoints( theNbPoints * nbArrows );
+ for ( int iP = 0, iA = 0; iA < nbArrows; ++iA )
+ for ( int i = 0; i < theNbPoints; ++i, ++iP )
+ aPoints->SetPoint( iP,
+ myUnitArrowPnts[i].X(),
+ myUnitArrowPnts[i].Y(),
+ myUnitArrowPnts[i].Z() );
+ myGrid->SetPoints(aPoints);
+ aPoints->Delete();
+
+ // connectivity of all arrows
+
+ const int theNbCells = ( theNbPoints - 1 ); // in one arrow
+ myGrid->Allocate( theNbCells * nbArrows );
+ for ( int nP = 0, iA = 0; iA < nbArrows; ++iA, nP += theNbPoints )
+ {
+ vtkIdType conn[3] = { theNbPoints - 1 + nP, // arrow end
+ theNbPoints - 3 + nP, // point on a circle
+ nP }; // point on a circle
+ for ( int i = 0; i < theNbCells-1; ++i )
+ {
+ myGrid->InsertNextCell( VTK_TRIANGLE, 3, conn );
+ conn[1] = conn[2];
+ conn[2] = conn[2] + 1;
+ }
+ conn[1] = theNbPoints - 2 + nP;
+ myGrid->InsertNextCell( VTK_LINE, 2, conn );
+ }
+
+ myLabelActors.resize( nbArrows, ( vtkTextActor*) NULL );
+ char label[] = "X";
+ if ( labels )
+ for ( int iA = 0; iA < nbArrows; ++iA )
+ {
+ label[0] = labels[iA];
+ vtkTextMapper* text = vtkTextMapper::New();
+ text->SetInput( label );
+ vtkCoordinate* coord = vtkCoordinate::New();
+
+ myLabelActors[iA] = vtkTextActor::New();
+ //myLabelActors[iA]->SetMapper( text );
+ myLabelActors[iA]->SetInput( label );
+ myLabelActors[iA]->SetTextScaleModeToNone();
+ myLabelActors[iA]->PickableOff();
+ myLabelActors[iA]->GetPositionCoordinate()->SetReferenceCoordinate( coord );
+
+ text->Delete();
+ coord->Delete();
+
+ myPreviewActor->GetRenderer()->AddActor(myLabelActors[iA]);
+ }
+}
+
+//================================================================================
+/*!
+ * \brief Set data to show moved/rotated/scaled arrows
+ * \param [in] axes - location and direction of the arrows
+ * \param [in] length - length of arrows
+ */
+//================================================================================
+
+void SMESHGUI_MeshEditPreview::SetArrows( const gp_Ax1* axes,
+ double length )
+{
+ vtkPoints* aPoints = myGrid->GetPoints();
+
+ for ( int iP = 0, iA = 0; iA < (int) myLabelActors.size(); ++iA )
+ {
+ gp_Trsf trsf;
+ trsf.SetTransformation( gp_Ax3( axes[iA].Location(), axes[iA].Direction() ), gp::XOY() );
+
+ for ( size_t i = 0; i < myUnitArrowPnts.size(); ++i, ++iP )
+ {
+ gp_Pnt p = myUnitArrowPnts[i].Scaled( gp::Origin(), length );
+ p.Transform( trsf );
+ aPoints->SetPoint( iP, p.X(), p.Y(), p.Z() );
+ }
+ if ( myLabelActors[iA] )
+ if ( vtkCoordinate* aCoord =
+ myLabelActors[iA]->GetPositionCoordinate()->GetReferenceCoordinate() )
+ {
+ double p[3];
+ aPoints->GetPoint( iP-1, p );
+ aCoord->SetValue( p );
+ }
+ }
+
+ myGrid->Modified();
+}
+