Tutorial OpenCASCADE Sketcher
Context and pointer to class object Sketcher_QtGUI is necessary to create Sketcher.
Handle(AIS_InteractiveContext) myContext;
Sketcher_QtGUI* mySG;
mySketcher = new Sketcher( myContext, mySG);
Sketcher set numerous parameters to default. To change it se following methods.
To set color:
Quantity_NameOfColor mycolor;
mySketcher.SetColor (mycolor);
To set type of object:
Sketcher_ObjectType mytype;
mySketcher.SetType (mytype);
To set line style of object:
Aspect_TypeOfLine mystyle;
mySketcher.SetStyle (mystyle);
To set line width:
Standard_Real mywidth;
mySketcher.SetWidth (mywidth);
To set precise during snap retrieval:
Standard_Real myprecise;
mySketcher.SetPrecise (myprecise);
To set context:
Handle(AIS_InteractiveContext) myContext;
mySketcher.SetContext (myContext);
To set current plane:
gp_Ax3 myCoordinateSystem(gp::Origin(),gp::DX());
mySketcher.SetCoordinateSystem (myCoordinateSystem);
List of objects can be set from outside the sketcher:
Handle(TColStd_HSequenceOfTransient) mydata;
mySketcher.SetData (mydata);
To get list of objects:
mySketcher.GetData ();
User choose entering object method to start input. It’s data must be delivered to Sketcher:
Sketcher_ObjectTypeOfMethod myMethod;
mySketcher.ObjectAction (myMethod);
After that point coordinates of cursor must be delivered to Sketcher.
Standard_Integer myX, myY; // point coordinates of cursor at window.
V3d_Coordinate my_v3dX,my_v3dY,my_v3dZ; //point coordinates at View
Quantity_Parameter projVx,projVy,projVz; //vector coordinates perpendicular
to screen at view
Handle(V3d_View) myView = myContext->CurrentViewer()->CreateView();
myView->Convert(myX,myY, my_v3dX,my_v3dY,my_v3dZ);
myView->Proj(projVx,projVy,projVz);
mySketcher.OnMouseMoveEvent(my_v3dX,my_v3dY,my_v3dZ,projVx,projVy,projVz);
To input point use another method:
Standard_Integer myX, myY; // point coordinates of cursor at window
V3d_Coordinate my_v3dX,my_v3dY,my_v3dZ;// point coordinates at View
Quantity_Parameter projVx,projVy,projVz; // vector coordinates perpendicular
to screen at view
Handle(V3d_View) myView = myContext->CurrentViewer()->CreateView();
myView->Convert(myX,myY, my_v3dX,my_v3dY,my_v3dZ);
myView->Proj(projVx,projVy,projVz);
mySketcher.OnMouseMoveEvent(my_v3dX,my_v3dY,my_v3dZ,projVx,projVy,projVz);
Cancel event handle by:
mySketcher.OnCancel();
To set Sketcher to polyline mode:
mySketcher.SetPolylineMode(Standard_True);
To unset polyline mode:
mySketcher.SetPolylineMode(Standard_False);
Default snap is SnapNothing. To set new snap:
Sketcher_SnapType sntype;
mySketcher.SetSnap (sntype);
To remove object from list of objects (only selected objects removing) use:
mySketcher.DeleteSelectedObject();
To edit object or view it’s property:
mySketcher.ViewProperties();
There is a method redraw all objects from list of objects:
mySketcher.RedrawAll();