1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

Integration of OCCT 6.5.0 from SVN

This commit is contained in:
bugmaster
2011-03-16 07:30:28 +00:00
committed by bugmaster
parent 4903637061
commit 7fd59977df
16375 changed files with 3882564 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
#include <ISession_Curve.ixx>
#include <GeomAdaptor_Curve.hxx>
#include <AIS_InteractiveObject.hxx>
#include <AIS_Drawer.hxx>
#include <StdPrs_PoleCurve.hxx>
#include <Prs3d_LineAspect.hxx>
#include <StdPrs_Curve.hxx>
ISession_Curve::ISession_Curve(const Handle(Geom_Curve)& aCurve)
:AIS_InteractiveObject(),myCurve(aCurve)
{
}
void ISession_Curve::Compute(const Handle(PrsMgr_PresentationManager3d)& ,const Handle(Prs3d_Presentation)& aPresentation,const Standard_Integer aMode)
{
GeomAdaptor_Curve anAdaptorCurve(myCurve);
Handle(AIS_Drawer) aDrawer = new AIS_Drawer();
aDrawer->LineAspect()->SetColor(Quantity_NOC_RED);
switch (aMode)
{
case 1 :
StdPrs_PoleCurve::Add(aPresentation, anAdaptorCurve,aDrawer);
case 0 :
StdPrs_Curve::Add( aPresentation, anAdaptorCurve ,myDrawer);
break;
}
}
void ISession_Curve::Compute(const Handle(Prs3d_Projector)& ,const Handle(Prs3d_Presentation)& )
{
}
void ISession_Curve::ComputeSelection(const Handle(SelectMgr_Selection)& ,const Standard_Integer )
{
}

View File

@@ -0,0 +1,90 @@
#include <ISession_Direction.ixx>
#include <Prs3d_ArrowAspect.hxx>
#include <gp_Pnt.hxx>
#include <DsgPrs_LengthPresentation.hxx>
#include <DsgPrs.hxx>
#include <Graphic2d_SetOfSegments.hxx>
#include <gp_Dir2d.hxx>
#include <AIS_Drawer.hxx>
ISession_Direction::ISession_Direction()
{
}
ISession_Direction::ISession_Direction(const gp_Pnt& aPnt,const gp_Dir& aDir,const Standard_Real aLength,const Standard_Real anArrowLength)
:myPnt(aPnt),myDir(aDir),myLength(aLength),myArrowLength(anArrowLength)
{
}
ISession_Direction::ISession_Direction(const gp_Pnt& aPnt,const gp_Vec& aVec,const Standard_Real aLength)
:myPnt(aPnt),myDir(aVec),myArrowLength(aLength)
{
myLength = aVec.Magnitude();
}
ISession_Direction::ISession_Direction(const gp_Pnt2d& aPnt2d,const gp_Dir2d& aDir2d,const Standard_Real aLength)
:myPnt(gp_Pnt(aPnt2d.X(),aPnt2d.Y(),0)),myDir(gp_Dir(aDir2d.X(),aDir2d.Y(),0)),myLength(aLength)
{
}
ISession_Direction::ISession_Direction(const gp_Pnt2d& aPnt2d,const gp_Vec2d& aVec2d)
:myPnt(gp_Pnt(aPnt2d.X(),aPnt2d.Y(),0)),myDir(gp_Dir(aVec2d.X(),aVec2d.Y(),0))
{
myLength = aVec2d.Magnitude();
}
void ISession_Direction::SetText(const TCollection_ExtendedString& aText)
{
myText = aText;
}
void ISession_Direction::Compute(const Handle(PrsMgr_PresentationManager3d)& ,const Handle(Prs3d_Presentation)& aPresentation,const Standard_Integer )
{
Handle(Prs3d_ArrowAspect) anArrowAspect = myDrawer->ArrowAspect();
anArrowAspect->SetLength(myArrowLength);
myDrawer->SetArrowAspect(anArrowAspect);
gp_Pnt LastPoint = myPnt;
LastPoint.Translate (myLength*gp_Vec(myDir));
if (myText.Length() == 0)
DsgPrs_LengthPresentation::Add(aPresentation,myDrawer,myPnt,LastPoint,DsgPrs_AS_LASTAR);
else
{
gp_Pnt OffsetPoint = myPnt;
OffsetPoint.Translate ((myLength) *gp_Vec(myDir));
DsgPrs_LengthPresentation::Add(aPresentation,myDrawer,myText,myPnt,LastPoint, -myDir, OffsetPoint, DsgPrs_AS_LASTAR);
}
}
void ISession_Direction::Compute(const Handle(Prs3d_Projector)& ,const Handle(Prs3d_Presentation)& )
{
}
void ISession_Direction::Compute(const Handle(PrsMgr_PresentationManager2d)& ,const Handle(Graphic2d_GraphicObject)& aGrObj,const Standard_Integer )
{
Handle(Graphic2d_SetOfSegments) segment;
segment = new Graphic2d_SetOfSegments(aGrObj);
segment->Add(myPnt.X(),
myPnt.Y(),
myPnt.X()+myLength*myDir.X(),
myPnt.Y()+myLength*myDir.Y());
gp_Dir2d aFirstDir = gp_Dir2d(myDir.X(),myDir.Y()).Rotated (200*PI180);
segment->Add(myPnt.X()+myLength*myDir.X(),
myPnt.Y()+myLength*myDir.Y(),
myPnt.X()+myLength*myDir.X()+ myLength*aFirstDir.X()/5,
myPnt.Y()+myLength*myDir.Y()+ myLength*aFirstDir.Y()/5);
gp_Dir2d aSecondDir = gp_Dir2d(myDir.X(),myDir.Y()).Rotated (-200*PI180);
segment->Add(myPnt.X()+myLength*myDir.X(),
myPnt.Y()+myLength*myDir.Y(),
myPnt.X()+myLength*myDir.X()+ myLength*aSecondDir.X()/5,
myPnt.Y()+myLength*myDir.Y()+ myLength*aSecondDir.Y()/5);
}
void ISession_Direction::ComputeSelection(const Handle(SelectMgr_Selection)& ,const Standard_Integer )
{
}

View File

@@ -0,0 +1,45 @@
#include <ISession_Point.ixx>
#include <Geom_CartesianPoint.hxx>
#include <StdPrs_Point.hxx>
#include <Graphic2d_CircleMarker.hxx>
ISession_Point::ISession_Point()
{
}
ISession_Point::ISession_Point(const Standard_Real X,const Standard_Real Y,const Standard_Real Z)
:myPoint(gp_Pnt(X,Y,Z))
{
}
ISession_Point::ISession_Point(const gp_Pnt2d& aPoint,const Standard_Real Elevation)
:myPoint(gp_Pnt(aPoint.X(),aPoint.Y(),Elevation))
{
}
ISession_Point::ISession_Point(const gp_Pnt& aPoint)
:myPoint(aPoint)
{
}
void ISession_Point::Compute(const Handle(PrsMgr_PresentationManager3d)& ,const Handle(Prs3d_Presentation)& aPresentation,const Standard_Integer )
{
Handle(Geom_CartesianPoint) aGeomPoint = new Geom_CartesianPoint(myPoint);
StdPrs_Point::Add(aPresentation,aGeomPoint,myDrawer);
}
void ISession_Point::Compute(const Handle(Prs3d_Projector)& ,const Handle(Prs3d_Presentation)& )
{
}
void ISession_Point::Compute(const Handle(PrsMgr_PresentationManager2d)& ,const Handle(Graphic2d_GraphicObject)& aGrObj,const Standard_Integer )
{
Handle(Graphic2d_CircleMarker) aCircleMarker;
aCircleMarker = new Graphic2d_CircleMarker(aGrObj,myPoint.X(),myPoint.Y(),0,0,1);
}
void ISession_Point::ComputeSelection(const Handle(SelectMgr_Selection)& ,const Standard_Integer )
{
}

View File

@@ -0,0 +1,49 @@
#include <ISession_Surface.ixx>
#include <AIS_InteractiveObject.hxx>
#include <GeomAdaptor_Surface.hxx>
#include <GeomAdaptor_HSurface.hxx>
#include <AIS_Drawer.hxx>
#include <Prs3d_LineAspect.hxx>
#include <StdPrs_ShadedSurface.hxx>
#include <StdPrs_WFPoleSurface.hxx>
#include <StdPrs_WFSurface.hxx>
ISession_Surface::ISession_Surface()
{
}
ISession_Surface::ISession_Surface(const Handle(Geom_Surface)& aSurface)
:AIS_InteractiveObject(),mySurface(aSurface)
{
}
void ISession_Surface::Compute(const Handle(PrsMgr_PresentationManager3d)& ,const Handle(Prs3d_Presentation)& aPresentation,const Standard_Integer aMode)
{
GeomAdaptor_Surface anAdaptorSurface(mySurface);
Handle(GeomAdaptor_HSurface) anAdaptorHSurface = new GeomAdaptor_HSurface(mySurface);
Handle(AIS_Drawer) aDrawer = new AIS_Drawer();
aDrawer->LineAspect()->SetColor(Quantity_NOC_YELLOW3);
switch (aMode)
{
case 2:
StdPrs_ShadedSurface::Add(aPresentation,anAdaptorSurface,myDrawer);
break;
case 1 :
StdPrs_WFPoleSurface::Add(aPresentation,anAdaptorSurface,aDrawer);
case 0 :
StdPrs_WFSurface::Add(aPresentation,anAdaptorHSurface,myDrawer);
break;
}
}
void ISession_Surface::Compute(const Handle(Prs3d_Projector)& ,const Handle(Prs3d_Presentation)& )
{
}
void ISession_Surface::ComputeSelection(const Handle(SelectMgr_Selection)& ,const Standard_Integer )
{
}

View File

@@ -0,0 +1,56 @@
#include <ISession_Text.ixx>
#include <AIS_InteractiveObject.hxx>
#include <Prs3d_Text.hxx>
#include <Graphic2d_Text.hxx>
ISession_Text::ISession_Text()
{
}
ISession_Text::ISession_Text(const TCollection_AsciiString& aText,const Standard_Real anX,const Standard_Real anY,const Standard_Real aZ,const Aspect_TypeOfText aType,const Quantity_PlaneAngle anAngle,const Standard_Real aSlant,const Standard_Integer aColorIndex,const Standard_Integer aFontIndex,const Quantity_Factor aScale)
: AIS_InteractiveObject(),MyText(aText),MyX(anX),MyY(anY),MyZ(aZ),
MyTypeOfText(aType),MyAngle(anAngle),MySlant(aSlant),
MyColorIndex(aColorIndex),MyFontIndex(aFontIndex),
MyScale(aScale),MyWidth(0),MyHeight(0)
{
}
ISession_Text::ISession_Text(const TCollection_AsciiString& aText,const gp_Pnt& aPoint,const Aspect_TypeOfText aType,const Quantity_PlaneAngle anAngle,const Standard_Real aSlant,const Standard_Integer aColorIndex,const Standard_Integer aFontIndex,const Quantity_Factor aScale)
:AIS_InteractiveObject(),MyText(aText),MyX(aPoint.X()),MyY(aPoint.Y()),MyZ(aPoint.Z()),
MyTypeOfText(aType),MyAngle(anAngle),MySlant(aSlant),
MyColorIndex(aColorIndex),MyFontIndex(aFontIndex),
MyScale(aScale),MyWidth(0),MyHeight(0)
{
}
void ISession_Text::Compute(const Handle(PrsMgr_PresentationManager3d)& ,const Handle(Prs3d_Presentation)& aPresentation,const Standard_Integer )
{
Prs3d_Text::Draw(aPresentation,myDrawer,MyText,gp_Pnt(MyX,MyY,MyZ));
}
void ISession_Text::Compute(const Handle(Prs3d_Projector)& ,const Handle(Prs3d_Presentation)& )
{
}
void ISession_Text::Compute(const Handle(PrsMgr_PresentationManager2d)& ,const Handle(Graphic2d_GraphicObject)& aGrObj,const Standard_Integer )
{
Handle(Graphic2d_Text) text;
text = new Graphic2d_Text(aGrObj, MyText, MyX, MyY, MyAngle, MyTypeOfText, MyScale);
text->SetFontIndex(MyFontIndex);
text->SetColorIndex(MyColorIndex);
text->SetSlant(MySlant);
text->SetUnderline(Standard_False);
text->SetZoomable(Standard_True);
aGrObj->Display();
Quantity_Length anXoffset,anYoffset;
text->TextSize(MyWidth, MyHeight,anXoffset,anYoffset);
}
void ISession_Text::ComputeSelection(const Handle(SelectMgr_Selection)& ,const Standard_Integer )
{
}

View File

@@ -0,0 +1,113 @@
#include <ISession2D_Curve.ixx>
#include <Geom2d_Curve.hxx>
#include <Geom2dAdaptor_Curve.hxx>
#include <Geom2d_BezierCurve.hxx>
#include <Geom2d_BSplineCurve.hxx>
#include <Geom2dLProp_CLProps2d.hxx>
#include <GGraphic2d_SetOfCurves.hxx>
#include <Graphic2d_Array1OfVertex.hxx>
#include <Graphic2d_Vertex.hxx>
#include <Graphic2d_Polyline.hxx>
#include <Graphic2d_Segment.hxx>
#include <gp_Pnt2d.hxx>
#include <TColStd_Array1OfReal.hxx>
ISession2D_Curve::ISession2D_Curve(const Handle(Geom2d_Curve)& aGeom2dCurve,const Aspect_TypeOfLine aTypeOfLine,const Aspect_WidthOfLine aWidthOfLine,const Standard_Integer aColorIndex)
:AIS_InteractiveObject()
{
myGeom2dCurve = aGeom2dCurve;
myTypeOfLine = aTypeOfLine;
myWidthOfLine = aWidthOfLine;
myColorIndex = aColorIndex;
myDisplayPole = Standard_True;
myDisplayCurbure = Standard_False;
myDiscretisation = 20;
myradiusmax = 10;
myradiusratio = 1;
}
void ISession2D_Curve::Compute(const Handle(PrsMgr_PresentationManager2d)& ,const Handle(Graphic2d_GraphicObject)& aGrObj,const Standard_Integer )
{
Handle(GGraphic2d_SetOfCurves) segment;
segment = new GGraphic2d_SetOfCurves(aGrObj);
segment->Add(myGeom2dCurve);
segment->SetColorIndex (myColorIndex);
segment->SetWidthIndex (myWidthOfLine + 1);
segment->SetTypeIndex (myTypeOfLine + 1);
Geom2dAdaptor_Curve anAdaptor(myGeom2dCurve);
if (myDisplayPole)
{
if (anAdaptor.GetType() == GeomAbs_BezierCurve)
{
Handle(Geom2d_BezierCurve) aBezier = anAdaptor.Bezier();
Graphic2d_Array1OfVertex anArrayOfVertex(1,aBezier->NbPoles());
for (int i=1;i<=aBezier->NbPoles();i++)
{
gp_Pnt2d CurrentPoint = aBezier->Pole(i);
Graphic2d_Vertex aVertex(CurrentPoint.X(),CurrentPoint.Y());
anArrayOfVertex(i) = aVertex;
}
Handle(Graphic2d_Polyline) aPolyline = new Graphic2d_Polyline(aGrObj, anArrayOfVertex);
}
if (anAdaptor.GetType() == GeomAbs_BSplineCurve)
{
Handle(Geom2d_BSplineCurve) aBSpline = anAdaptor.BSpline();
Graphic2d_Array1OfVertex anArrayOfVertex(1,aBSpline->NbPoles());
for (int i=1;i<=aBSpline->NbPoles();i++)
{
gp_Pnt2d CurrentPoint = aBSpline->Pole(i);
Graphic2d_Vertex aVertex(CurrentPoint.X(),CurrentPoint.Y());
anArrayOfVertex(i) = aVertex;
}
Handle(Graphic2d_Polyline) aPolyline = new Graphic2d_Polyline(aGrObj,anArrayOfVertex);
}
}
if (myDisplayCurbure && (anAdaptor.GetType() != GeomAbs_Line))
{
Standard_Integer ii;
Standard_Integer intrv, nbintv = anAdaptor.NbIntervals(GeomAbs_CN);
TColStd_Array1OfReal TI(1,nbintv+1);
anAdaptor.Intervals(TI,GeomAbs_CN);
Standard_Real Resolution = 1.0e-9, Curvature;
Geom2dLProp_CLProps2d LProp(myGeom2dCurve, 2, Resolution);
gp_Pnt2d P1, P2;
for (intrv=1; intrv<=nbintv; intrv++)
{
Standard_Real t = TI(intrv);
Standard_Real step = (TI(intrv+1) - t) / GetDiscretisation();
Standard_Real LRad, ratio;
for (ii = 1; ii <= myDiscretisation; ii++)
{
LProp.SetParameter(t);
if (LProp.IsTangentDefined())
{
Curvature = Abs(LProp.Curvature());
if (Curvature > Resolution)
{
myGeom2dCurve->D0(t, P1);
LRad = 1./Curvature;
ratio = ((LRad>myradiusmax)?myradiusmax/LRad:1);
ratio *= myradiusratio;
LProp.CentreOfCurvature(P2);
gp_Vec2d V(P1,P2);
gp_Pnt2d P3 = P1.Translated(ratio*V);
Handle(Graphic2d_Segment) aSegment = new Graphic2d_Segment(aGrObj,P1.X(),P1.Y(),P3.X(),P3.Y());
}
}
t += step;
}
}
}
}
void ISession2D_Curve::ComputeSelection(const Handle(SelectMgr_Selection)& ,const Standard_Integer )
{
}

View File

@@ -0,0 +1,429 @@
#include <ISession2D_InteractiveContext.ixx>
#include <ISession2D_ObjectOwner.hxx>
#include <V2d_Viewer.hxx>
#include <V2d_View.hxx>
#include <AIS_InteractiveObject.hxx>
#include <AIS_Shape.hxx>
#include <PrsMgr_PresentationManager2d.hxx>
#include <SelectMgr_SelectionManager.hxx>
#include <SelectMgr_SelectableObject.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <StdSelect_ViewerSelector2d.hxx>
#include <StdSelect_TextProjector2d.hxx>
#include <TColStd_MapIteratorOfMapOfTransient.hxx>
#include <Graphic2d_Buffer.hxx>
ISession2D_InteractiveContext::ISession2D_InteractiveContext()
{
}
ISession2D_InteractiveContext::ISession2D_InteractiveContext(const Handle(V2d_Viewer)& aViewer)
{
Initialize(aViewer);
}
void ISession2D_InteractiveContext::Initialize(const Handle(V2d_Viewer)& aViewer)
{
myViewer = aViewer;
myPrsmgr = new PrsMgr_PresentationManager2d(myViewer->View());
mySelectionManager = new SelectMgr_SelectionManager();
mySelector = new StdSelect_ViewerSelector2d();
mySelector->Set(3);
// set Sensitivity very very important for SensitiveCurve !!
mySelector->SetSensitivity (0.5); // en mm
mySelectionManager->Add(mySelector);
myHilightColorIndex = 5; // for dynamic highlight
IsAreasDisplayed = Standard_False;
myPrsmgr->SetHighlightColor(8); // For Static highlight
}
void ISession2D_InteractiveContext::Display(const Handle(AIS_InteractiveObject)& anObject,
const Standard_Boolean Redraw)
{
myObjects.Add(anObject);
Standard_Integer DispMode ,HiMode,SelMode;
GetDefModes(anObject,DispMode ,HiMode,SelMode);
myPrsmgr->Display(anObject,DispMode);
mySelectionManager->Load(anObject,mySelector);
mySelectionManager->Activate(anObject,SelMode,mySelector);
if (Redraw)
myViewer->Update();
}
void ISession2D_InteractiveContext::Display(const Handle(AIS_InteractiveObject)& anObject,
const Standard_Integer aDisplayMode,
const Standard_Integer aSelectionMode,
const Standard_Boolean Redraw)
{
myObjects.Add(anObject);
anObject->SetDisplayMode(aDisplayMode);
anObject->SetSelectionMode(aSelectionMode);
myObjects.Add(anObject);
myPrsmgr->Display(anObject,aDisplayMode);
mySelectionManager->Load(anObject,mySelector);
mySelectionManager->Activate(anObject,aSelectionMode,mySelector);
if (Redraw) myViewer->Update();
}
void ISession2D_InteractiveContext::Erase(const Handle(AIS_InteractiveObject)& anObject,
const Standard_Boolean Redraw)
{
if (myObjects.Contains(anObject)) {
Standard_Integer DispMode ,HiMode,SelMode;
GetDefModes(anObject,DispMode ,HiMode,SelMode);
myPrsmgr->Erase(anObject,DispMode);
mySelectionManager->Deactivate(anObject,mySelector);
if (Redraw) myViewer->Update();
}
}
void ISession2D_InteractiveContext::DisplayAll(const Standard_Boolean Redraw)
{
TColStd_MapIteratorOfMapOfTransient It(myObjects);
for(;It.More();It.Next()){
Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast(It.Key());
Standard_Integer DispMode ,HiMode,SelMode;
GetDefModes(anObject,DispMode ,HiMode,SelMode);
myPrsmgr->Display(anObject,DispMode);
mySelectionManager->Load(anObject,mySelector);
mySelectionManager->Activate(anObject,HiMode,mySelector);
}
if (Redraw) myViewer->Update();
}
void ISession2D_InteractiveContext::EraseAll(const Standard_Boolean Redraw)
{
TColStd_MapIteratorOfMapOfTransient It(myObjects);
for(;It.More();It.Next()){
Handle(AIS_InteractiveObject) anObject = Handle(AIS_InteractiveObject)::DownCast(It.Key());
Standard_Integer DispMode ,HiMode,SelMode;
GetDefModes(anObject,DispMode ,HiMode,SelMode);
myPrsmgr->Erase(anObject,DispMode);
mySelectionManager->Deactivate(anObject,mySelector);
}
if (Redraw) myViewer->Update();
}
Standard_Boolean ISession2D_InteractiveContext::IsDisplayed(const Handle(AIS_InteractiveObject)& anObject,
const Standard_Integer aMode)
{
return myPrsmgr->IsDisplayed(anObject,aMode);
}
void ISession2D_InteractiveContext::Redisplay(const Handle(AIS_InteractiveObject)& anObject,
const Standard_Boolean Redraw,
const Standard_Boolean )
{
if (myObjects.Contains(anObject)) {
Standard_Integer DispMode ,HiMode,SelMode;
GetDefModes(anObject,DispMode ,HiMode,SelMode);
myPrsmgr->Update(anObject,DispMode);
// WARNING : IMPLEMENTATION IS NOT FINISH !!!!!!!!
// NEED TO UPDATE THE OTHER MODES, AND SELECTION !!!!!
// mySelectionManager->Load(anObject,mySelector);
// mySelectionManager->Activate(anObject,SelMode,mySelector);
if (Redraw) myViewer->Update();
}
}
void ISession2D_InteractiveContext::Clear(const Handle(AIS_InteractiveObject)& ,
const Standard_Boolean )
{
Standard_Failure::Raise("NotYetImplemented");
}
void ISession2D_InteractiveContext::Remove(const Handle(AIS_InteractiveObject)& anObject,
const Standard_Boolean Redraw)
{
if (myObjects.Contains(anObject)) {
Erase(anObject,Redraw);
myObjects.Remove(anObject);
}
}
void ISession2D_InteractiveContext::Highlight(const Handle(AIS_InteractiveObject)& anObject,
const Standard_Boolean Redraw)
{
if (myObjects.Contains(anObject)) {
Standard_Integer DispMode ,HiMode,SelMode;
GetDefModes(anObject,DispMode ,HiMode,SelMode);
myPrsmgr->Highlight(anObject,HiMode);
if(Redraw) myViewer->Update();
}
}
void ISession2D_InteractiveContext::Unhighlight(const Handle(AIS_InteractiveObject)& anObject,
const Standard_Boolean Redraw)
{
if (myObjects.Contains(anObject)) {
Standard_Integer DispMode ,HiMode,SelMode;
GetDefModes(anObject,DispMode ,HiMode,SelMode);
myPrsmgr->Unhighlight(anObject,HiMode);
if(Redraw) myViewer->Update();
}
}
Standard_Boolean ISession2D_InteractiveContext::IsHilighted(const Handle(AIS_InteractiveObject)& anObject)
{
if (myObjects.Contains(anObject)) {
Standard_Integer DispMode ,HiMode,SelMode;
GetDefModes(anObject,DispMode ,HiMode,SelMode);
return myPrsmgr->IsHighlighted(anObject,HiMode);
}
return Standard_False;
}
Standard_Boolean ISession2D_InteractiveContext::NewProjector(const Handle(V2d_View)& aView,
Handle(Select2D_Projector)& NewProjector)
{
// to be changed : here we build a new projector each time.
// or we have to define a new one only if we change :
// the View
// the view zoom factor
// the view panning
// the fonts changes.
NewProjector = new StdSelect_TextProjector2d(aView);
return Standard_True;
}
// Manage Detected : update The Display
void ISession2D_InteractiveContext::ManageDetected(TColStd_MapOfTransient& aNewMapOfDetectedOwner)
{
Standard_Boolean NeedRedraw = Standard_False;
//======================================================================
// Treatement on the old Selection :
// for each owner :
// if the object is decomposed : Unhighlight the Owner,
// else Unhighlight the Object,except if selected
//======================================================================
TColStd_MapIteratorOfMapOfTransient anIterator(myMapOfDetectedOwner);
for (;anIterator.More();anIterator.Next())
{
// for all owner :
Handle(ISession2D_ObjectOwner) TheOwner =
Handle(ISession2D_ObjectOwner)::DownCast(anIterator.Key());
Handle(AIS_InteractiveObject) TheObject =
Handle(AIS_InteractiveObject)::DownCast(TheOwner->Selectable());
// if the owner is not still detected
if (!aNewMapOfDetectedOwner.Contains(TheOwner))
{
NeedRedraw = Standard_True;
// if the corresponding object is a Shape and is not Decomposed
Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(TheObject);
Standard_Boolean TreatementOnCompleteObject = Standard_True;
if (!anAISShape.IsNull())
if (anAISShape->AcceptShapeDecomposition() && anAISShape->HasSelectionMode())
TreatementOnCompleteObject = Standard_False;
if(TreatementOnCompleteObject)
{
// if the corresponding object is not Selected
if (!myMapOfSelectedOwner.Contains(TheOwner))
{
Standard_Integer DispMode ,HiMode,SelMode;
GetDefModes(TheObject,DispMode ,HiMode,SelMode);
if ( myPrsmgr->IsHighlighted(TheObject))
myPrsmgr->Unhighlight(TheObject,HiMode);
}
}
else
{
// UnHighlight the old detected Owner,
TheOwner->Unhilight(myPrsmgr);
}
}
}
//======================================================================
// Treatement on the New Selection
//======================================================================
anIterator.Initialize(aNewMapOfDetectedOwner);
for (;anIterator.More();anIterator.Next())
{
// for all owner :
Handle(ISession2D_ObjectOwner) TheOwner =
Handle(ISession2D_ObjectOwner)::DownCast(anIterator.Key());
Handle(AIS_InteractiveObject) TheObject =
Handle(AIS_InteractiveObject)::DownCast(TheOwner->Selectable());
// if the owner is not alwraidy detected
if (!myMapOfDetectedOwner.Contains(TheOwner))
{
NeedRedraw = Standard_True;
// if the corresponding object is a Shape and is not Decomposed
Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(TheObject);
Standard_Boolean TreatementOnCompleteObject = Standard_True;
if (!anAISShape.IsNull())
if (anAISShape->AcceptShapeDecomposition() && anAISShape->HasSelectionMode())
TreatementOnCompleteObject = Standard_False;
if(TreatementOnCompleteObject)
{
// if the corresponding object is not Selected
if (!myMapOfSelectedOwner.Contains(TheOwner))
{
Standard_Integer DispMode ,HiMode,SelMode;
GetDefModes(TheObject,DispMode ,HiMode,SelMode);
if (!myPrsmgr->IsHighlighted(TheObject))
myPrsmgr->ColorHighlight(TheObject,myHilightColorIndex,HiMode);
}
}
else
{
// The Object Is Decomposed --> Specific Treatement on the owner
TheOwner->Hilight(myPrsmgr);
}
}
}
//======================================================================
// set the new detected map
//======================================================================
// set The new detected Owner
myMapOfDetectedOwner = aNewMapOfDetectedOwner;
if (NeedRedraw) myViewer->Update();
}
void ISession2D_InteractiveContext::Move(const Standard_Integer x1,
const Standard_Integer y1,
const Handle(V2d_View)& aView)
{
Handle(Select2D_Projector) aProjector;
if (NewProjector(aView,aProjector)) // if we need a new projector
mySelector->Set(aProjector);
mySelector->Pick(x1,y1,aView);
TColStd_MapOfTransient aNewMapOfDetectedOwner;
mySelector->Init();
if(mySelector->More())
{
Handle(SelectMgr_EntityOwner) aOwner = mySelector->OnePicked();
if (aOwner->IsKind(STANDARD_TYPE(ISession2D_ObjectOwner))) {
Handle(ISession2D_ObjectOwner) aNewDetectedObjectOwner =
Handle(ISession2D_ObjectOwner)::DownCast(aOwner);
aNewMapOfDetectedOwner.Add(aNewDetectedObjectOwner);
}
}
ManageDetected(aNewMapOfDetectedOwner);
}
void ISession2D_InteractiveContext::Move(const Standard_Integer x1,
const Standard_Integer y1,
const Standard_Integer x2,
const Standard_Integer y2,
const Handle(V2d_View)& aView)
{
Handle(Select2D_Projector) aProjector;
if (NewProjector(aView,aProjector)) // if we need a new projector
mySelector->Set(aProjector);
mySelector->Pick(x1,y1,x2,y2,aView);
TColStd_MapOfTransient aNewMapOfDetectedOwner;
for(mySelector->Init();mySelector->More();mySelector->Next())
{
Handle(SelectMgr_EntityOwner) aOwner = mySelector->Picked();
if (aOwner->IsKind(STANDARD_TYPE(ISession2D_ObjectOwner))) {
Handle(ISession2D_ObjectOwner) aNewDetectedObjectOwner =
Handle(ISession2D_ObjectOwner)::DownCast(aOwner);
aNewMapOfDetectedOwner.Add(aNewDetectedObjectOwner);
}
}
ManageDetected(aNewMapOfDetectedOwner);
}
void ISession2D_InteractiveContext::Pick(const Standard_Boolean MultiSelection)
{
// We have a Map of all the seletected owners : myMapOfSelectedOwner;
// if we are not in MultiSelection.
// UnHighLight and keep out the map all the last selected objects
if (!MultiSelection)
{
TColStd_MapIteratorOfMapOfTransient anIterator(myMapOfSelectedOwner);
for (;anIterator.More();anIterator.Next())
{
Handle(ISession2D_ObjectOwner) TheOwner =
Handle(ISession2D_ObjectOwner)::DownCast(anIterator.Key());
Handle(AIS_InteractiveObject) TheObject =
Handle(AIS_InteractiveObject)::DownCast(TheOwner->Selectable());
// UnHighLight The Last Selected ObjectObject.
Unhighlight(TheObject, // Object
Standard_False); // Redraw
}
myMapOfSelectedOwner.Clear();
}
TColStd_MapIteratorOfMapOfTransient anIterator(myMapOfDetectedOwner);
for (;anIterator.More();anIterator.Next())
{
// for all owner :
Handle(ISession2D_ObjectOwner) TheOwner =
Handle(ISession2D_ObjectOwner)::DownCast(anIterator.Key());
myMapOfSelectedOwner.Add(TheOwner);
Handle(AIS_InteractiveObject) TheObject =
Handle(AIS_InteractiveObject)::DownCast(TheOwner->Selectable());
Highlight(TheObject, // Object
Standard_False); // Redraw
}
myViewer->Update();
}
void ISession2D_InteractiveContext::GetDefModes(const Handle(AIS_InteractiveObject)& anObject,
Standard_Integer& DispMode,
Standard_Integer& HiMode,
Standard_Integer& SelMode) const
{
DispMode = anObject->HasDisplayMode() ? anObject->DisplayMode() :
anObject->DefaultDisplayMode();
HiMode = anObject->HasHilightMode() ? anObject->HilightMode() : DispMode;
SelMode = anObject->HasSelectionMode() ? anObject->SelectionMode() : 0;
}
void ISession2D_InteractiveContext::DisplayAreas()
{
if (IsAreasDisplayed) return;
myViewer->InitActiveViews();
while(myViewer->MoreActiveViews())
{
Handle(V2d_View) aView = myViewer->ActiveView();
mySelector->DisplayAreas(aView);
myViewer->NextActiveViews();
}
myViewer->Update();
IsAreasDisplayed= Standard_True;
}
void ISession2D_InteractiveContext::ClearAreas()
{
if (!IsAreasDisplayed) return;
mySelector->ClearAreas();
myViewer->Update();
IsAreasDisplayed= Standard_False;
}

View File

@@ -0,0 +1,43 @@
#include <ISession2D_ObjectOwner.ixx>
#include <PrsMgr_PresentationManager2d.hxx>
#include <Graphic2d_Text.hxx>
ISession2D_ObjectOwner::ISession2D_ObjectOwner(const Standard_Integer aPriority)
:SelectMgr_EntityOwner(aPriority)
{
}
ISession2D_ObjectOwner::ISession2D_ObjectOwner(const Handle(SelectMgr_SelectableObject)& aSO,
const Standard_Integer aPriority)
:SelectMgr_EntityOwner(aSO,aPriority)
{
}
// Presentation Management
void ISession2D_ObjectOwner::Hilight(const Handle(PrsMgr_PresentationManager)& aPM,
const Standard_Integer )
{
if (aPM->IsKind(STANDARD_TYPE(PrsMgr_PresentationManager2d))) {
if (myGo.IsNull())
{
Handle(Graphic2d_View) aView = Handle(PrsMgr_PresentationManager2d)::DownCast(aPM)->StructureManager();
myGo = new Graphic2d_GraphicObject(aView);
}
Handle(Graphic2d_Text) text;
text = new Graphic2d_Text(myGo, myDumpMessage, 0, 0, 0,Aspect_TOT_SOLID,1.5);
text->SetZoomable(Standard_False);
myGo->Display();
}
}
void ISession2D_ObjectOwner::Unhilight(const Handle(PrsMgr_PresentationManager)& ,
const Standard_Integer )
{
if (myGo.IsNull()) return;
myGo->RemovePrimitives();
myGo->Display();
myGo->Remove();
}

View File

@@ -0,0 +1,99 @@
#include <ISession2D_SensitiveCurve.ixx>
#include <Geom2dAdaptor_Curve.hxx>
#include <GCPnts_TangentialDeflection.hxx>
#include <gp_Pnt.hxx>
#include <Bnd_Box2d.hxx>
#include <SelectBasics_BasicTool.hxx>
#include <TColgp_HArray1OfPnt2d.hxx>
#include <SelectBasics_ListOfBox2d.hxx>
ISession2D_SensitiveCurve::ISession2D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,const Handle(Geom2d_Curve)& C,const Standard_Real CDeflect,const Standard_Integer MaxRect)
:Select2D_SensitiveEntity(OwnerId),
myCDeflect(CDeflect),
myMaxRect(MaxRect),
myCurve(C)
{
Compute();
}
void ISession2D_SensitiveCurve::Compute()
{
Geom2dAdaptor_Curve Curve (myCurve);
Standard_Real ADeflect = 180; //Angular deflection
GCPnts_TangentialDeflection PointsOnCurve;
PointsOnCurve.Initialize (Curve, ADeflect, myCDeflect,myMaxRect,1.0e-9);
myPolyP2d = new TColgp_HArray1OfPnt2d(1,PointsOnCurve.NbPoints());
gp_Pnt P;
for (Standard_Integer i=1; i<=PointsOnCurve.NbPoints();i++)
{
P = PointsOnCurve.Value (i);
myPolyP2d->SetValue(i,gp_Pnt2d(P.X(),P.Y()));
}
}
void ISession2D_SensitiveCurve::Areas(SelectBasics_ListOfBox2d& aSeq)
{
// calcul des Areas --> le nombre voulu est myMaxRect
// mais il y a myPolyP2d->Length() segments
Standard_Integer NbSeg = myPolyP2d->Length()-1;
Standard_Integer nbPerBoxes= NbSeg/myMaxRect;
Standard_Integer CurrentPoint =1;
for (Standard_Integer i=1;i<=myMaxRect-1;i++)
{
Bnd_Box2d abox;
abox.Set(myPolyP2d->Value(CurrentPoint));
for(Standard_Integer j=1;j<=nbPerBoxes;j++)
{
CurrentPoint++;
abox.Add(myPolyP2d->Value(CurrentPoint));
}
aSeq.Append(abox);
}
Bnd_Box2d abox;
abox.Set(myPolyP2d->Value(CurrentPoint));
for(Standard_Integer j=CurrentPoint;j<=myPolyP2d->Length()-1;j++)
{
CurrentPoint++;
abox.Add(myPolyP2d->Value(CurrentPoint));
}
aSeq.Append(abox);
}
Standard_Boolean ISession2D_SensitiveCurve::Matches(const Standard_Real XMin,const Standard_Real YMin,const Standard_Real XMax,const Standard_Real YMax,const Standard_Real aTol)
{
Bnd_Box2d BoundBox;
BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
for(Standard_Integer j=1;j<=myPolyP2d->Length()-1;j++)
{
if(BoundBox.IsOut(myPolyP2d->Value(j))) return Standard_False;
}
return Standard_True;
}
Standard_Boolean ISession2D_SensitiveCurve::Matches(const Standard_Real X,const Standard_Real Y,const Standard_Real aTol,Standard_Real& DMin)
{
// VERY VERY IMPORTANT : set the selector sensibility !!! ( it's aTol !! )
Standard_Integer Rank = 0;
Standard_Boolean Result = SelectBasics_BasicTool::MatchPolyg2d(myPolyP2d->Array1(),
X,Y,
aTol,
DMin,
Rank);
return Result;
}
Handle(TColgp_HArray1OfPnt2d) ISession2D_SensitiveCurve::SensitivePolygon()
{
return myPolyP2d;
}

View File

@@ -0,0 +1,278 @@
#include <ISession2D_Shape.ixx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#include <HLRBRep_PolyHLRToShape.hxx>
#include <HLRBRep_HLRToShape.hxx>
#include <TopExp_Explorer.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Vertex.hxx>
#include <BRep_Tool.hxx>
#include <TopExp.hxx>
#include <Geom2d_TrimmedCurve.hxx>
ISession2D_Shape::ISession2D_Shape()
:AIS_InteractiveObject(PrsMgr_TOP_ProjectorDependant)
{
}
void ISession2D_Shape::Add(const TopoDS_Shape& aShape)
{
myListOfShape.Append(aShape);
myAlgo.Nullify();
myPolyAlgo.Nullify();
Update(); // protected method used to specify that the presentation are not up to date
}
void ISession2D_Shape::SetProjector(HLRAlgo_Projector& aProjector)
{
myProjector= aProjector;
myAlgo.Nullify();
myPolyAlgo.Nullify();
Update(); // protected method used to specify that the presentation are not up to date
}
void ISession2D_Shape::SetNbIsos(const Standard_Integer aNbIsos)
{
myNbIsos= aNbIsos;
myAlgo.Nullify();
Standard_Integer i;
// declare the mode 100 to 110 as non valid
for (i=100;i<=110;i++)
Update(i,Standard_False); // protected method used to specify that the presentation are not up to date
// declare the mode 1100 to 1110 as non valid
for (i=1100;i<=1110;i++)
Update(i,Standard_False); // protected method used to specify that the presentation are not up to date
}
void ISession2D_Shape::BuildAlgo()
{
myAlgo = new HLRBRep_Algo();
TopTools_ListIteratorOfListOfShape anIterator(myListOfShape);
for (;anIterator.More();anIterator.Next()) myAlgo->Add(anIterator.Value(),myNbIsos);
myAlgo->Projector(myProjector);
myAlgo->Update();
myAlgo->Hide();
}
void ISession2D_Shape::BuildPolyAlgo()
{
myPolyAlgo = new HLRBRep_PolyAlgo();
TopTools_ListIteratorOfListOfShape anIterator(myListOfShape);
for (;anIterator.More();anIterator.Next()) myPolyAlgo->Load(anIterator.Value());
myPolyAlgo->Projector(myProjector);
myPolyAlgo->Update();
}
void ISession2D_Shape::Compute(const Handle(PrsMgr_PresentationManager3d)& ,
const Handle(Prs3d_Presentation)& ,
const Standard_Integer )
{
}
void ISession2D_Shape::Compute(const Handle(Prs3d_Projector)& ,
const Handle(Prs3d_Presentation)& )
{
}
void ISession2D_Shape::Compute(const Handle(PrsMgr_PresentationManager2d)& ,
const Handle(Graphic2d_GraphicObject)& aGrObj,
const Standard_Integer aMode)
{
Standard_Integer TheMode = aMode;
Standard_Boolean DrawHiddenLine= Standard_True;
if (TheMode >= 1000)
{
DrawHiddenLine = Standard_False;
TheMode -= 1000;
}
Standard_Boolean UsePolyAlgo= Standard_True;
if (TheMode >= 100)
{
UsePolyAlgo = Standard_False;
TheMode -= 100;
}
TopoDS_Shape VCompound;
TopoDS_Shape Rg1LineVCompound;
TopoDS_Shape RgNLineVCompound;
TopoDS_Shape OutLineVCompound;
TopoDS_Shape IsoLineVCompound; // only fro Exact algo
TopoDS_Shape HCompound;
TopoDS_Shape Rg1LineHCompound;
TopoDS_Shape RgNLineHCompound;
TopoDS_Shape OutLineHCompound;
TopoDS_Shape IsoLineHCompound; // only fro Exact algo
if (UsePolyAlgo)
{
if (myPolyAlgo.IsNull()) BuildPolyAlgo();
HLRBRep_PolyHLRToShape aPolyHLRToShape;
aPolyHLRToShape.Update(myPolyAlgo);
VCompound = aPolyHLRToShape.VCompound();
Rg1LineVCompound = aPolyHLRToShape.Rg1LineVCompound();
RgNLineVCompound = aPolyHLRToShape.RgNLineVCompound();
OutLineVCompound = aPolyHLRToShape.OutLineVCompound();
HCompound = aPolyHLRToShape.HCompound();
Rg1LineHCompound = aPolyHLRToShape.Rg1LineHCompound();
RgNLineHCompound = aPolyHLRToShape.RgNLineHCompound();
OutLineHCompound = aPolyHLRToShape.OutLineHCompound();
}
else
{
if (myAlgo.IsNull()) BuildAlgo();
HLRBRep_HLRToShape aHLRToShape(myAlgo);
VCompound = aHLRToShape.VCompound();
Rg1LineVCompound = aHLRToShape.Rg1LineVCompound();
RgNLineVCompound = aHLRToShape.RgNLineVCompound();
OutLineVCompound = aHLRToShape.OutLineVCompound();
IsoLineVCompound = aHLRToShape.IsoLineVCompound();
HCompound = aHLRToShape.HCompound();
Rg1LineHCompound = aHLRToShape.Rg1LineHCompound();
RgNLineHCompound = aHLRToShape.RgNLineHCompound();
OutLineHCompound = aHLRToShape.OutLineHCompound();
IsoLineHCompound = aHLRToShape.IsoLineHCompound();
}
if (UsePolyAlgo)
{
Handle(Graphic2d_SetOfSegments) aSetOfVSegmentsHighLighted = new Graphic2d_SetOfSegments(aGrObj);
Handle(Graphic2d_SetOfSegments) aSetOfVSegments = new Graphic2d_SetOfSegments(aGrObj);
if (TheMode == 1) DrawCompound(VCompound , aSetOfVSegmentsHighLighted);
else DrawCompound(VCompound , aSetOfVSegments);
if (TheMode == 2) DrawCompound(Rg1LineVCompound , aSetOfVSegmentsHighLighted);
else DrawCompound(Rg1LineVCompound , aSetOfVSegments);
if (TheMode == 3) DrawCompound(RgNLineVCompound , aSetOfVSegmentsHighLighted);
else DrawCompound(RgNLineVCompound , aSetOfVSegments);
if (TheMode == 4) DrawCompound(OutLineVCompound , aSetOfVSegmentsHighLighted);
else DrawCompound(OutLineVCompound , aSetOfVSegments);
aSetOfVSegmentsHighLighted->SetColorIndex (1);
aSetOfVSegmentsHighLighted->SetWidthIndex (1);
aSetOfVSegmentsHighLighted->SetTypeIndex (1);
aSetOfVSegments->SetColorIndex (2);
aSetOfVSegments->SetWidthIndex (2);
if (DrawHiddenLine)
{
Handle(Graphic2d_SetOfSegments) aSetOfHSegmentsHighLighted = new Graphic2d_SetOfSegments(aGrObj);
Handle(Graphic2d_SetOfSegments) aSetOfHSegments = new Graphic2d_SetOfSegments(aGrObj);
if (TheMode == 6) DrawCompound(HCompound , aSetOfHSegmentsHighLighted);
else DrawCompound(HCompound , aSetOfHSegments);
if (TheMode == 7) DrawCompound(Rg1LineHCompound , aSetOfHSegmentsHighLighted);
else DrawCompound(Rg1LineHCompound , aSetOfHSegments);
if (TheMode == 8) DrawCompound(RgNLineHCompound , aSetOfHSegmentsHighLighted);
else DrawCompound(RgNLineHCompound , aSetOfHSegments);
if (TheMode == 9) DrawCompound(OutLineHCompound , aSetOfHSegmentsHighLighted);
else DrawCompound(OutLineHCompound , aSetOfHSegments);
aSetOfVSegments->SetTypeIndex (2);
aSetOfHSegmentsHighLighted->SetColorIndex (3);
aSetOfHSegmentsHighLighted->SetWidthIndex (3);
aSetOfHSegmentsHighLighted->SetTypeIndex (3);
aSetOfHSegments->SetColorIndex (4);
aSetOfHSegments->SetWidthIndex (4);
aSetOfHSegments->SetTypeIndex (4);
}
}
else
{
Handle(GGraphic2d_SetOfCurves) aSetOfVCurvesHighLighted = new GGraphic2d_SetOfCurves(aGrObj);
Handle(GGraphic2d_SetOfCurves) aSetOfVCurves = new GGraphic2d_SetOfCurves(aGrObj);
if (TheMode == 1) DrawCompound(VCompound , aSetOfVCurvesHighLighted);
else DrawCompound(VCompound , aSetOfVCurves);
if (TheMode == 2) DrawCompound(Rg1LineVCompound , aSetOfVCurvesHighLighted);
else DrawCompound(Rg1LineVCompound , aSetOfVCurves);
if (TheMode == 3) DrawCompound(RgNLineVCompound , aSetOfVCurvesHighLighted);
else DrawCompound(RgNLineVCompound , aSetOfVCurves);
if (TheMode == 4) DrawCompound(OutLineVCompound , aSetOfVCurvesHighLighted);
else DrawCompound(OutLineVCompound , aSetOfVCurves);
if (TheMode == 5) DrawCompound(IsoLineVCompound , aSetOfVCurvesHighLighted);
else DrawCompound(IsoLineVCompound , aSetOfVCurves);
aSetOfVCurvesHighLighted->SetColorIndex (1);
aSetOfVCurvesHighLighted->SetWidthIndex (1);
aSetOfVCurvesHighLighted->SetTypeIndex (1);
aSetOfVCurves->SetColorIndex (2);
aSetOfVCurves->SetWidthIndex (2);
aSetOfVCurves->SetTypeIndex (2);
if (DrawHiddenLine)
{
Handle(GGraphic2d_SetOfCurves) aSetOfHCurvesHighLighted = new GGraphic2d_SetOfCurves(aGrObj);
Handle(GGraphic2d_SetOfCurves) aSetOfHCurves = new GGraphic2d_SetOfCurves(aGrObj);
if (TheMode == 6) DrawCompound(HCompound , aSetOfHCurvesHighLighted);
else DrawCompound(HCompound , aSetOfHCurves);
if (TheMode == 7) DrawCompound(Rg1LineHCompound , aSetOfHCurvesHighLighted);
else DrawCompound(Rg1LineHCompound , aSetOfHCurves);
if (TheMode == 8) DrawCompound(RgNLineHCompound , aSetOfHCurvesHighLighted);
else DrawCompound(RgNLineHCompound , aSetOfHCurves);
if (TheMode == 9) DrawCompound(OutLineHCompound , aSetOfHCurvesHighLighted);
else DrawCompound(OutLineHCompound , aSetOfHCurves);
if (TheMode == 10) DrawCompound(IsoLineHCompound , aSetOfHCurvesHighLighted);
else DrawCompound(IsoLineHCompound , aSetOfHCurves);
aSetOfHCurvesHighLighted->SetColorIndex (3);
aSetOfHCurvesHighLighted->SetWidthIndex (3);
aSetOfHCurvesHighLighted->SetTypeIndex (3);
aSetOfHCurves->SetColorIndex (4);
aSetOfHCurves->SetWidthIndex (4);
aSetOfHCurves->SetTypeIndex (4);
}
}
}
void ISession2D_Shape::DrawCompound(const TopoDS_Shape& aCompound,
const Handle(Graphic2d_SetOfSegments)& aSetOfSegments)
{
if (aCompound.IsNull())
return;
TopExp_Explorer ex(aCompound,TopAbs_EDGE);
while (ex.More()) {
const TopoDS_Edge& CurrentEdge = TopoDS::Edge(ex.Current());
const TopoDS_Vertex& FirstVertex=TopExp::FirstVertex(CurrentEdge);
const TopoDS_Vertex& LastVertex =TopExp::LastVertex(CurrentEdge);
gp_Pnt FirstPoint = BRep_Tool::Pnt(FirstVertex);
gp_Pnt LastPoint = BRep_Tool::Pnt(LastVertex);
aSetOfSegments->Add(FirstPoint.X(),FirstPoint.Y(),LastPoint.X(),LastPoint.Y());
ex.Next();
}
}
void ISession2D_Shape::DrawCompound(const TopoDS_Shape& aCompound,
const Handle(GGraphic2d_SetOfCurves)& aSetOfCurves)
{
if (aCompound.IsNull())
return;
TopExp_Explorer ex(aCompound,TopAbs_EDGE);
Handle(Geom2d_Curve) aCurve;
Handle(Geom_Surface) aSurface;
TopLoc_Location L;
Standard_Real f,l;
while (ex.More()) {
const TopoDS_Edge& CurrentEdge = TopoDS::Edge(ex.Current());
if (CurrentEdge.Location().IsIdentity()) {
BRep_Tool::CurveOnSurface(CurrentEdge,aCurve,aSurface,L,f,l);
if (L.IsIdentity()) {
Handle(Geom2d_TrimmedCurve) c= new Geom2d_TrimmedCurve(aCurve,f,l);
if (!c.IsNull())
aSetOfCurves->Add(c);
}
}
ex.Next();
}
}
void ISession2D_Shape::ComputeSelection(const Handle(SelectMgr_Selection)& ,
const Standard_Integer )
{
}

View File

@@ -0,0 +1,151 @@
#include <SampleAISBasicPackage.hxx>
#include <TCollection_AsciiString.hxx>
#include <AIS_InteractiveContext.hxx>
#include <AIS_Shape.hxx>
#include <AIS_Trihedron.hxx>
#include <AIS_Circle.hxx>
#include <AIS_Line.hxx>
#include <User_Cylinder.hxx>
#include <Geom_Line.hxx>
#include <Geom_Axis2Placement.hxx>
#include <GC_MakeCircle.hxx>
#include <gp_Pnt.hxx>
#include <gp_Lin.hxx>
#include <gp_Dir.hxx>
#include <BRepPrimAPI_MakeSphere.hxx>
#include <V3d_Viewer.hxx>
#include <V3d_View.hxx>
#ifdef WNT
#include <WNT_Window.hxx>
#include <Graphic3d_WNTGraphicDevice.hxx>
#else
#include <Xw_Window.hxx>
#include <Graphic3d_GraphicDevice.hxx>
#endif
//===============================================================
// Function name: CreateViewer
//===============================================================
Handle(V3d_Viewer) SampleAISBasicPackage::CreateViewer (const Standard_ExtString aName)
{
#ifdef WNT
static Handle(Graphic3d_WNTGraphicDevice) defaultDevice;
if (defaultDevice.IsNull())
defaultDevice = new Graphic3d_WNTGraphicDevice();
return new V3d_Viewer(defaultDevice, aName);
#else
static Handle(Graphic3d_GraphicDevice) defaultDevice;
if (defaultDevice.IsNull())
defaultDevice = new Graphic3d_GraphicDevice("");
return new V3d_Viewer(defaultDevice, aName);
#endif //WNT
}
//===============================================================
// Function name: SetWindow
//===============================================================
void SampleAISBasicPackage::SetWindow (const Handle(V3d_View)& aView,
const Standard_Integer hiwin,
const Standard_Integer lowin)
{
#ifdef WNT
Handle(Graphic3d_WNTGraphicDevice) d =
Handle(Graphic3d_WNTGraphicDevice)::DownCast(aView->Viewer()->Device());
Handle(WNT_Window) w = new WNT_Window(d,hiwin,lowin);
#else
Handle(Graphic3d_GraphicDevice) d =
Handle(Graphic3d_GraphicDevice)::DownCast(aView->Viewer()->Device());
Handle(Xw_Window) w = new Xw_Window(d,hiwin,lowin,Xw_WQ_3DQUALITY);
#endif
aView->SetWindow(w);
}
void SampleAISBasicPackage::DisplayTrihedron(const Handle(AIS_InteractiveContext)& aContext)
{
Handle(AIS_Trihedron) aTrihedron;
Handle(Geom_Axis2Placement) anAxis=new Geom_Axis2Placement(gp::XOY());
aTrihedron=new AIS_Trihedron(anAxis);
aContext->Display(aTrihedron);
}
void SampleAISBasicPackage::DisplayCircle(const Handle(AIS_InteractiveContext)& aContext,
TCollection_AsciiString& Message)
{
GC_MakeCircle C(gp_Pnt(-100.,-300.,0.),gp_Pnt(-50.,-200.,0.),gp_Pnt(-10.,-250.,0.));
Handle(AIS_Circle) anAISCirc = new AIS_Circle(C.Value());
aContext->Display(anAISCirc);
Message = "\
\n\
GC_MakeCircle C(gp_Pnt(-100.,-300.,0.),gp_Pnt(-50.,-200.,0.),gp_Pnt(-10.,-250.,0.)); \n\
Handle(AIS_Circle) anAISCirc = new AIS_Circle(C.Value()); \n\
myAISContext->Display(anAISCirc); \n\
\n";
}
void SampleAISBasicPackage::DisplayLine(const Handle(AIS_InteractiveContext)& aContext,
TCollection_AsciiString& Message)
{
gp_Lin L(gp_Pnt(0.,0.,0.),gp_Dir(1.,0.,0.));
Handle(Geom_Line) aLine = new Geom_Line(L);
Handle(AIS_Line) anAISLine = new AIS_Line(aLine);
aContext->Display(anAISLine);
Message = "\
\n\
gp_Lin L(gp_Pnt(0.,0.,0.),gp_Dir(1.,0.,0.)); \n\
Handle(Geom_Line) aLine = new Geom_Line(L); \n\
Handle(AIS_Line) anAISLine = new AIS_Line(aLine); \n\
myAISContext->Display(anAISLine); \n\
\n";
}
void SampleAISBasicPackage::DisplaySphere(const Handle(AIS_InteractiveContext)& aContext,
TCollection_AsciiString& Message)
{
BRepPrimAPI_MakeSphere S(gp_Pnt(200.,300.,200.), 100.);
Handle(AIS_Shape) anAISShape = new AIS_Shape(S.Shape());
aContext->SetColor(anAISShape,Quantity_NOC_AZURE);
aContext->SetMaterial(anAISShape,Graphic3d_NOM_PLASTIC);
aContext->SetDisplayMode(anAISShape,1);
aContext->Display(anAISShape);
Message = "\
\n\
BRepPrimAPI_MakeSphere S(gp_Pnt(200.,300.,200.), 100.); \n\
Handle(AIS_Shape) anAISShape = new AIS_Shape(S.Shape()); \n\
myAISContext->SetColor(anAISShape,Quantity_NOC_AZURE); \n\
myAISContext->SetMaterial(anAISShape,Graphic3d_NOM_PLASTIC); \n\
myAISContext->SetDisplayMode(anAISShape,1); \n\
myAISContext->Display(anAISShape); \n\
\n";
}
void SampleAISBasicPackage::DisplayCylinder(const Handle(AIS_InteractiveContext)& aContext,
TCollection_AsciiString& Message)
{
Handle(User_Cylinder) aCyl = new User_Cylinder(100.,200.);
aContext->SetDisplayMode(aCyl,1);
aContext->Display(aCyl);
Message = "\
\n\
Handle(User_Cylinder) aCyl = new User_Cylinder(100.,200.); \n\
myAISContext->SetDisplayMode(aCyl,1); \n\
myAISContext->Display(aCyl); \n\
\n\
NOTE: a User_Cylinder is an object defined by the user. \n\
The User_Cylinder class inherits the AIS_InteractiveObject \n\
CASCADE class, its usage is the same as an AIS_InteractiveObject. \n\
\n";
}

View File

@@ -0,0 +1,424 @@
#include <SampleAISDisplayModePackage.hxx>
#include <TCollection_AsciiString.hxx>
#include <AIS_InteractiveContext.hxx>
#include <AIS_Shape.hxx>
#include <User_Cylinder.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <BRepPrimAPI_MakeSphere.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <Quantity_Color.hxx>
#include <V3d_Viewer.hxx>
#include <V3d_View.hxx>
#include <V3d_DirectionalLight.hxx>
#include <Prs3d_Drawer.hxx>
#include <Prs3d_ShadingAspect.hxx>
#include <Prs3d_IsoAspect.hxx>
#include <gp_Pnt.hxx>
#include <gp_Dir.hxx>
#include <gp_Vec.hxx>
#include <gp_Pln.hxx>
#include <gp_Pnt2d.hxx>
#include <ProjLib.hxx>
#include <ElSLib.hxx>
#include <Precision.hxx>
#ifdef WNT
#include <WNT_Window.hxx>
#include <Graphic3d_WNTGraphicDevice.hxx>
#else
#include <Xw_Window.hxx>
#include <Graphic3d_GraphicDevice.hxx>
#endif
/*----------------------------------------------------------------------*/
Handle(V3d_DirectionalLight) aLight;
Handle(AIS_Shape) aShape;
gp_Pnt p1, p2;
//===============================================================
// Function name: CreateViewer
//===============================================================
Handle(V3d_Viewer) SampleAISDisplayModePackage::CreateViewer (const Standard_ExtString aName)
{
#ifdef WNT
static Handle(Graphic3d_WNTGraphicDevice) defaultDevice;
if (defaultDevice.IsNull())
defaultDevice = new Graphic3d_WNTGraphicDevice();
return new V3d_Viewer(defaultDevice, aName);
#else
static Handle(Graphic3d_GraphicDevice) defaultDevice;
if (defaultDevice.IsNull())
defaultDevice = new Graphic3d_GraphicDevice("");
return new V3d_Viewer(defaultDevice, aName);
#endif //WNT
}
//===============================================================
// Function name: SetWindow
//===============================================================
void SampleAISDisplayModePackage::SetWindow (const Handle(V3d_View)& aView,
const Standard_Integer hiwin,
const Standard_Integer lowin)
{
#ifdef WNT
Handle(Graphic3d_WNTGraphicDevice) d =
Handle(Graphic3d_WNTGraphicDevice)::DownCast(aView->Viewer()->Device());
Handle(WNT_Window) w = new WNT_Window(d,hiwin,lowin);
#else
Handle(Graphic3d_GraphicDevice) d =
Handle(Graphic3d_GraphicDevice)::DownCast(aView->Viewer()->Device());
Handle(Xw_Window) w = new Xw_Window(d,hiwin,lowin,Xw_WQ_3DQUALITY);
#endif
aView->SetWindow(w);
}
/*----------------------------------------------------------------------*/
gp_Pnt ConvertClickToPoint(Standard_Real x, Standard_Real y, Handle(V3d_View) aView)
{
V3d_Coordinate XEye,YEye,ZEye,XAt,YAt,ZAt;
aView->Eye(XEye,YEye,ZEye);
aView->At(XAt,YAt,ZAt);
gp_Pnt EyePoint(XEye,YEye,ZEye);
gp_Pnt AtPoint(XAt,YAt,ZAt);
gp_Vec EyeVector(EyePoint,AtPoint);
gp_Dir EyeDir(EyeVector);
gp_Pln PlaneOfTheView = gp_Pln(AtPoint,EyeDir);
V3d_Coordinate X,Y,Z;
aView->Convert(Standard_Integer(x),Standard_Integer(y),X,Y,Z);
gp_Pnt ConvertedPoint(X,Y,Z);
gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project(PlaneOfTheView,ConvertedPoint);
gp_Pnt ResultPoint = ElSLib::Value(ConvertedPointOnPlane.X(),
ConvertedPointOnPlane.Y(),
PlaneOfTheView);
return ResultPoint;
}
//======================================================================
//= =
//= Display objects =
//= =
//======================================================================
//===============================================================
// Function name: DisplayBox
//===============================================================
void SampleAISDisplayModePackage::DisplayBox(const Handle(AIS_InteractiveContext)& aContext,
TCollection_AsciiString& Message)
{
BRepPrimAPI_MakeBox B(gp_Pnt(-400.,-400.,-100.),200.,150.,100.);
Handle(AIS_Shape) aBox = new AIS_Shape(B.Shape());
aContext->Display(aBox);
Message = "\
\n\
BRepPrimAPI_MakeBox B(gp_Pnt(-400.,-400.,-100.),200.,150.,100.); \n\
Handle(AIS_Shape) aBox = new AIS_Shape(B.Shape()); \n\
myAISContext->Display(aBox); \n\
\n";
}
//===============================================================
// Function name: DisplaySphere
//===============================================================
void SampleAISDisplayModePackage::DisplaySphere(const Handle(AIS_InteractiveContext)& aContext,
TCollection_AsciiString& Message)
{
BRepPrimAPI_MakeSphere S(gp_Pnt(200.,300.,200.), 100.);
Handle(AIS_Shape) anAISShape = new AIS_Shape(S.Shape());
aContext->Display(anAISShape);
Message = "\
\n\
BRepPrimAPI_MakeSphere S(gp_Pnt(200.,300.,200.), 100.); \n\
Handle(AIS_Shape) anAISShape = new AIS_Shape(S.Shape()); \n\
myAISContext->Display(anAISShape); \n\
\n";
}
//===============================================================
// Function name: DisplayCylinder
//===============================================================
void SampleAISDisplayModePackage::DisplayCylinder(const Handle(AIS_InteractiveContext)& aContext,
TCollection_AsciiString& Message)
{
Handle(User_Cylinder) aCyl = new User_Cylinder(100.,200.);
aContext->SetDisplayMode(aCyl,1);
aContext->Display(aCyl);
Message = "\
\n\
Handle(User_Cylinder) aCyl = new User_Cylinder(100.,200.); \n\
myAISContext->SetDisplayMode(aCyl,1); \n\
myAISContext->Display(aCyl); \n\
\n\
NOTE: a User_Cylinder is an object defined by the user. \n\
The User_Cylinder class inherits the AIS_InteractiveObject \n\
CASCADE class, its usage is the same as an AIS_InteractiveObject. \n\
\n";
}
//===============================================================
// Function name: EraseAll
//===============================================================
void SampleAISDisplayModePackage::EraseAll(const Handle(AIS_InteractiveContext)& aContext,
TCollection_AsciiString& Message)
{
aContext->EraseAll(Standard_False);
Message = "\
\n\
myAISContext->EraseAll(Standard_False); \n\
\n";
}
//======================================================================
//= =
//= Context properties =
//= =
//======================================================================
//===============================================================
// Function name: InitContext
//===============================================================
void SampleAISDisplayModePackage::InitContext(const Handle(AIS_InteractiveContext)& aContext)
{
aContext->DefaultDrawer()->ShadingAspect()->SetColor(Quantity_NOC_CHARTREUSE1);
aContext->DefaultDrawer()->ShadingAspect()->SetMaterial(Graphic3d_NOM_SILVER);
}
//===============================================================
// Function name: GetIsosNumber
//===============================================================
void SampleAISDisplayModePackage::GetIsosNumber(const Handle(AIS_InteractiveContext)& aContext,
Standard_Integer& u,Standard_Integer& v)
{
u = aContext->DefaultDrawer()->UIsoAspect()->Number();
v = aContext->DefaultDrawer()->VIsoAspect()->Number();
}
//===============================================================
// Function name: SetIsosNumber
//===============================================================
void SampleAISDisplayModePackage::SetIsosNumber(const Handle(AIS_InteractiveContext)& aContext,
const Standard_Integer u,
const Standard_Integer v,
TCollection_AsciiString& Message)
{
aContext->DefaultDrawer()->UIsoAspect()->SetNumber(u);
aContext->DefaultDrawer()->VIsoAspect()->SetNumber(v);
Message = "\
\n\
myAISContext->DefaultDrawer()->UIsoAspect()->SetNumber(u); \n\
myAISContext->DefaultDrawer()->VIsoAspect()->SetNumber(v); \n\
\n";
}
//===============================================================
// Function name: SetDisplayMode
//===============================================================
void SampleAISDisplayModePackage::SetDisplayMode(const Handle(AIS_InteractiveContext)& aContext,
const AIS_DisplayMode aMode,
TCollection_AsciiString& Message)
{
aContext->SetDisplayMode(aMode);
Message = "\
\n\
myAISContext->SetDisplayMode(aMode); \n\
\n";
}
//======================================================================
//= =
//= Object properties =
//= =
//======================================================================
//===============================================================
// Function name: SetObjectDisplayMode
//===============================================================
void SampleAISDisplayModePackage::SetObjectDisplayMode(const Handle(AIS_InteractiveContext)& aContext,
const AIS_DisplayMode aMode,
TCollection_AsciiString& Message)
{
for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
aContext->SetDisplayMode(aContext->Current(), aMode);
Message = "\
\n\
for (myAISContext->InitCurrent(); myAISContext->MoreCurrent(); \n\
myAISContext->NextCurrent()) \n\
myAISContext->SetDisplayMode(myAISContext->Current(), aMode); \n\
\n";
}
//===============================================================
// Function name: SetObjectMaterial
//===============================================================
void SampleAISDisplayModePackage::SetObjectMaterial(const Handle(AIS_InteractiveContext)& aContext,
const Graphic3d_NameOfMaterial aName,
TCollection_AsciiString& Message)
{
for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
aContext->SetMaterial(aContext->Current(), aName);
Message = "\
\n\
for (myAISContext->InitCurrent(); myAISContext->MoreCurrent(); \n\
myAISContext->NextCurrent()) \n\
myAISContext->SetMaterial(myAISContext->Current(), aName); \n\
\n";
}
//===============================================================
// Function name: GetObjectColor
//===============================================================
Quantity_Color SampleAISDisplayModePackage::GetObjectColor(const Handle(AIS_InteractiveContext)& aContext)
{
Handle(AIS_InteractiveObject) Current;
Quantity_Color aColor;
aContext->InitCurrent();
if (aContext->MoreCurrent()) {
Current = aContext->Current();
if (Current->HasColor())
aColor = Current->Color();
}
return aColor;
}
//===============================================================
// Function name: SetObjectColor
//===============================================================
void SampleAISDisplayModePackage::SetObjectColor(const Handle(AIS_InteractiveContext)& aContext,
const Quantity_Color& aColor,
TCollection_AsciiString& Message)
{
for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
aContext->SetColor(aContext->Current(), aColor.Name());
Message = "\
\n\
for (myAISContext->InitCurrent(); myAISContext->MoreCurrent(); \n\
myAISContext->NextCurrent()) \n\
myAISContext->SetColor(myAISContext->Current(), aColor.Name()); \n\
\n";
}
//===============================================================
// Function name: GetObjectTransparency
//===============================================================
Standard_Real SampleAISDisplayModePackage::GetObjectTransparency(const Handle(AIS_InteractiveContext)& aContext)
{
Standard_Real aValue = 0.0;
aContext->InitCurrent();
if (aContext->MoreCurrent())
aValue = aContext->Current()->Transparency();
return aValue;
}
//===============================================================
// Function name: SetObjectTransparency
//===============================================================
void SampleAISDisplayModePackage::SetObjectTransparency(const Handle(AIS_InteractiveContext)& aContext,
const Standard_Real aValue,
TCollection_AsciiString& Message)
{
for (aContext->InitCurrent(); aContext->MoreCurrent(); aContext->NextCurrent())
aContext->SetTransparency(aContext->Current(), aValue);
Message = "\
\n\
for (myAISContext->InitCurrent(); myAISContext->MoreCurrent(); \n\
myAISContext->NextCurrent()) \n\
myAISContext->SetTransparency(myAISContext->Current(), aValue); \n\
\n";
}
//======================================================================
//= =
//= Light =
//= =
//======================================================================
//===============================================================
// Function name: CreateLight
//===============================================================
void SampleAISDisplayModePackage::CreateLight(const Handle(AIS_InteractiveContext)& aContext)
{
aContext->OpenLocalContext();
}
//===============================================================
// Function name: SetFirstPointOfLight
//===============================================================
void SampleAISDisplayModePackage::SetFirstPointOfLight(const Handle(AIS_InteractiveContext)& aContext,
const Handle(V3d_View)& aView,
const Standard_Integer X,
const Standard_Integer Y)
{
p1 = ConvertClickToPoint(X,Y,aView);
// Create a directional light
aLight = new V3d_DirectionalLight(aView->Viewer(), p1.X(),p1.Y(),p1.Z(),0.,0.,1.);
p2 = gp_Pnt(p1.X(),p1.Y(),p1.Z()+1.);
BRepBuilderAPI_MakeEdge E(p1, p2);
aShape = new AIS_Shape(E.Edge());
aShape->SetColor(Quantity_NOC_YELLOW);
aContext->Display(aShape);
// Activate the light in the view
aView->SetLightOn(aLight);
}
//===============================================================
// Function name: MoveSecondPointOfLight
//===============================================================
void SampleAISDisplayModePackage::MoveSecondPointOfLight(const Handle(AIS_InteractiveContext)& aContext,
const Handle(V3d_View)& aView,
const Standard_Integer X,
const Standard_Integer Y)
{
p2 = ConvertClickToPoint(X,Y,aView);
if (p1.Distance(p2)>Precision::Confusion()) {
BRepBuilderAPI_MakeEdge E(p1, p2);
aShape->Set(E.Edge());
aContext->Redisplay(aShape);
//Update the light dynamically
aLight->SetDirection(p2.X()-p1.X(),p2.Y()-p1.Y(),p2.Z()-p1.Z());
aView->UpdateLights();
}
}
//===============================================================
// Function name: SetSecondPointOfLight
//===============================================================
void SampleAISDisplayModePackage::SetSecondPointOfLight(const Handle(AIS_InteractiveContext)& aContext)
{
aContext->CloseLocalContext();
}

View File

@@ -0,0 +1,329 @@
#include <SampleAISSelectPackage.hxx>
#include <TCollection_AsciiString.hxx>
#include <AIS_InteractiveContext.hxx>
#include <AIS_InteractiveObject.hxx>
#include <AIS_Shape.hxx>
#include <User_Cylinder.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <BRepFilletAPI_MakeFillet.hxx>
#include <gp_Pnt.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Shape.hxx>
#include <Geom_Surface.hxx>
#include <Geom_Plane.hxx>
#include <BRep_Tool.hxx>
#include <Quantity_Color.hxx>
#include <V3d_Viewer.hxx>
#include <V3d_View.hxx>
#ifdef WNT
#include <WNT_Window.hxx>
#include <Graphic3d_WNTGraphicDevice.hxx>
#else
#include <Xw_Window.hxx>
#include <Graphic3d_GraphicDevice.hxx>
#endif
//===============================================================
// Function name: CreateViewer
//===============================================================
Handle(V3d_Viewer) SampleAISSelectPackage::CreateViewer (const Standard_ExtString aName)
{
#ifdef WNT
static Handle(Graphic3d_WNTGraphicDevice) defaultDevice;
if (defaultDevice.IsNull())
defaultDevice = new Graphic3d_WNTGraphicDevice();
return new V3d_Viewer(defaultDevice, aName);
#else
static Handle(Graphic3d_GraphicDevice) defaultDevice;
if (defaultDevice.IsNull())
defaultDevice = new Graphic3d_GraphicDevice("");
return new V3d_Viewer(defaultDevice, aName);
#endif //WNT
}
//===============================================================
// Function name: SetWindow
//===============================================================
void SampleAISSelectPackage::SetWindow (const Handle(V3d_View)& aView,
const Standard_Integer hiwin,
const Standard_Integer lowin)
{
#ifdef WNT
Handle(Graphic3d_WNTGraphicDevice) d =
Handle(Graphic3d_WNTGraphicDevice)::DownCast(aView->Viewer()->Device());
Handle(WNT_Window) w = new WNT_Window(d,hiwin,lowin);
#else
Handle(Graphic3d_GraphicDevice) d =
Handle(Graphic3d_GraphicDevice)::DownCast(aView->Viewer()->Device());
Handle(Xw_Window) w = new Xw_Window(d,hiwin,lowin,Xw_WQ_3DQUALITY);
#endif
aView->SetWindow(w);
}
//===============================================================
// Function name: DisplayBox
//===============================================================
void SampleAISSelectPackage::DisplayBox(const Handle(AIS_InteractiveContext)& aContext,
TCollection_AsciiString& Message)
{
aContext->CloseAllContexts();
BRepPrimAPI_MakeBox B(gp_Pnt(-400.,-400.,-100.),200.,150.,100.);
Handle(AIS_Shape) aBox = new AIS_Shape(B.Shape());
aContext->Display(aBox);
Message = "\
\n\
BRepPrimAPI_MakeBox B(gp_Pnt(-400.,-400.,-100.),200.,150.,100.); \n\
Handle(AIS_Shape) aBox = new AIS_Shape(B.Shape()); \n\
myAISContext->Display(aBox); \n\
\n";
}
//===============================================================
// Function name: DisplayCylinder
//===============================================================
void SampleAISSelectPackage::DisplayCylinder(const Handle(AIS_InteractiveContext)& aContext,
TCollection_AsciiString& Message)
{
aContext->CloseAllContexts();
Handle(User_Cylinder) aCyl = new User_Cylinder(100.,200.);
aContext->SetDisplayMode(aCyl,1);
aContext->Display(aCyl);
Message = "\
\n\
Handle(User_Cylinder) aCyl = new User_Cylinder(100.,200.); \n\
myAISContext->SetDisplayMode(aCyl,1); \n\
myAISContext->Display(aCyl); \n\
\n\
NOTE: a User_Cylinder is an object defined by the user. \n\
The User_Cylinder class inherits the AIS_InteractiveObject \n\
CASCADE class, its usage is the same as an AIS_InteractiveObject. \n\
\n";
}
//===============================================================
// Function name: SelectVertices
//===============================================================
void SampleAISSelectPackage::SelectVertices(const Handle(AIS_InteractiveContext)& aContext,
TCollection_AsciiString& Message)
{
aContext->CloseAllContexts();
aContext->OpenLocalContext();
aContext->ActivateStandardMode(TopAbs_VERTEX);
Message = "\
\n\
myAISContext->OpenLocalContext(); \n\
myAISContext->ActivateStandardMode(TopAbs_VERTEX); \n\
\n";
}
//===============================================================
// Function name: SelectEdges
//===============================================================
void SampleAISSelectPackage::SelectEdges(const Handle(AIS_InteractiveContext)& aContext,
TCollection_AsciiString& Message)
{
aContext->CloseAllContexts();
aContext->OpenLocalContext();
aContext->ActivateStandardMode(TopAbs_EDGE);
Message = "\
\n\
myAISContext->OpenLocalContext(); \n\
myAISContext->ActivateStandardMode(TopAbs_EDGE); \n\
\n";
}
//===============================================================
// Function name: SelectFaces
//===============================================================
void SampleAISSelectPackage::SelectFaces(const Handle(AIS_InteractiveContext)& aContext,
TCollection_AsciiString& Message)
{
aContext->CloseAllContexts();
aContext->OpenLocalContext();
aContext->ActivateStandardMode(TopAbs_FACE);
Message = "\
\n\
myAISContext->OpenLocalContext(); \n\
myAISContext->ActivateStandardMode(TopAbs_FACE); \n\
\n";
}
//===============================================================
// Function name: SelectNeutral
//===============================================================
void SampleAISSelectPackage::SelectNeutral(const Handle(AIS_InteractiveContext)& aContext,
TCollection_AsciiString& Message)
{
aContext->CloseAllContexts();
Message = "\
\n\
myAISContext->CloseAllContexts(); \n\
\n";
}
//===============================================================
// Function name: MakeFillet
//===============================================================
Standard_Integer SampleAISSelectPackage::MakeFillet(const Handle(AIS_InteractiveContext)& aContext,
const Standard_Real aValue,
TCollection_AsciiString& Message)
{
aContext->InitSelected();
if(aContext->MoreSelected()) {
Handle(AIS_Shape) S = Handle(AIS_Shape)::DownCast(aContext->SelectedInteractive());
if(S.IsNull()) {
return 2;
}
BRepFilletAPI_MakeFillet aFillet(S->Shape());
for (aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected())
{
TopoDS_Shape aLocalShape = aContext->SelectedShape();
TopoDS_Edge anEdge;
if(aLocalShape.ShapeType() == TopAbs_EDGE) {
anEdge = TopoDS::Edge(aLocalShape);
}
if (anEdge.IsNull())
return 2;
aFillet.Add(aValue, anEdge);
}
TopoDS_Shape aNewShape;
try {
aNewShape = aFillet.Shape();
}
catch(Standard_Failure) {
return 1;
}
S->Set(aNewShape);
aContext->Redisplay(S);
Message = "\
\n\
Handle(AIS_Shape) S = Handle(AIS_Shape)::DownCast(myAISContext->SelectedInteractive()); \n\
BRepFilletAPI_MakeFillet aFillet(S->Shape()); \n\
\n\
for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected()) \n\
{ \n\
TopoDS_Edge anEdge = TopoDS::Edge(myAISContext->SelectedShape()); \n\
aFillet.Add(aValue, anEdge); \n\
} \n\
\n\
TopoDS_Shape aNewShape; \n\
\n\
aNewShape = aFillet.Shape(); \n\
\n\
S->Set(aNewShape); \n\
myAISContext->Redisplay(S); \n\
\n";
return 0;
}
return 2;
}
//===============================================================
// Function name: IsCylinderSelected
//===============================================================
Standard_Boolean SampleAISSelectPackage::IsCylinderSelected(const Handle(AIS_InteractiveContext)& aContext)
{
Standard_Boolean result = Standard_False;
aContext->InitCurrent();
if (aContext->MoreCurrent()) {
if (aContext->Current()->IsKind(STANDARD_TYPE(User_Cylinder)))
result = Standard_True;
}
return result;
}
//===============================================================
// Function name: StartSelectFace
//===============================================================
void SampleAISSelectPackage::StartSelectFace(const Handle(AIS_InteractiveContext)& aContext)
{
aContext->OpenLocalContext();
aContext->Activate(aContext->Current(),4);
}
//===============================================================
// Function name: GetFaceColor
//===============================================================
Quantity_Color SampleAISSelectPackage::GetFaceColor(const Handle(AIS_InteractiveContext)& aContext)
{
Quantity_Color aColor(Quantity_NOC_WHITE);
aContext->InitSelected();
if (aContext->MoreSelected()) {
Handle(AIS_InteractiveObject) Current = aContext->SelectedInteractive();
if (Current->HasColor())
aColor = aContext->Color(Current);
}
return aColor;
}
//===============================================================
// Function name: SetFaceColor
//===============================================================
void SampleAISSelectPackage::SetFaceColor(const Handle(AIS_InteractiveContext)& aContext,
const Quantity_Color& aColor,
TCollection_AsciiString& Message)
{
TopoDS_Shape S = aContext->SelectedShape();
Handle(Geom_Surface) Surface = BRep_Tool::Surface(TopoDS::Face(S));
if (Surface->IsKind(STANDARD_TYPE(Geom_Plane)))
Handle(User_Cylinder)::DownCast(aContext->Current())->SetPlanarFaceColor(aColor.Name());
else
Handle(User_Cylinder)::DownCast(aContext->Current())->SetCylindricalFaceColor(aColor.Name());
aContext->Redisplay(aContext->Current());
Message = "\
\n\
TopoDS_Shape S = myAISContext->SelectedShape(); \n\
Handle(Geom_Surface) Surface = BRep_Tool::Surface(TopoDS::Face(S)); \n\
\n\
if (Surface->IsKind(STANDARD_TYPE(Geom_Plane))) \n\
Handle(User_Cylinder)::DownCast(myAISContext->Current())->SetPlanarFaceColor(aColor.Name()); \n\
else \n\
Handle(User_Cylinder)::DownCast(myAISContext->Current())->SetCylindricalFaceColor(aColor.Name()); \n\
\n\
myAISContext->Redisplay(myAISContext->Current()); \n\
\n\
\n\
NOTE: a User_Cylinder is an object defined by the user. \n\
The User_Cylinder class inherits the AIS_InteractiveObject \n\
CASCADE class, its usage is the same as an AIS_InteractiveObject. \n\
Methods SetPlanarFaceColor and SetCylindricalFaceColor are also \n\
defined in the User_Cylinder class. \n\
\n";
}
//===============================================================
// Function name: EndSelectFace
//===============================================================
void SampleAISSelectPackage::EndSelectFace(const Handle(AIS_InteractiveContext)& aContext)
{
aContext->CloseLocalContext();
}

View File

@@ -0,0 +1,251 @@
#include <SampleDisplayAnimationPackage.hxx>
#include <AIS_InteractiveContext.hxx>
#include <AIS_Shape.hxx>
#include <TopoDS_Shape.hxx>
#include <BRep_Builder.hxx>
#include <BRepTools.hxx>
#include <TCollection_AsciiString.hxx>
#include <gp_Pnt.hxx>
#include <gp_Dir.hxx>
#include <gp_Vec.hxx>
#include <gp_Ax1.hxx>
#include <gp_Ax3.hxx>
#include <gp_Trsf.hxx>
#include <V3d_Viewer.hxx>
#include <V3d_View.hxx>
#ifdef WNT
#include <WNT_Window.hxx>
#include <Graphic3d_WNTGraphicDevice.hxx>
#else
#include <Xw_Window.hxx>
#include <Graphic3d_GraphicDevice.hxx>
#endif
/*----------------------------------------------------------------------*/
Handle(AIS_Shape) myAISCrankArm;
Handle(AIS_Shape) myAISCylinderHead;
Handle(AIS_Shape) myAISPropeller;
Handle(AIS_Shape) myAISPiston;
Handle(AIS_Shape) myAISEngineBlock;
Standard_Real myDeviation;
Standard_Integer myAngle;
Standard_Integer thread;
//===============================================================
// Function name: CreateViewer
//===============================================================
Handle(V3d_Viewer) SampleDisplayAnimationPackage::CreateViewer(const Standard_ExtString aName)
{
#ifdef WNT
static Handle(Graphic3d_WNTGraphicDevice) defaultDevice;
if (defaultDevice.IsNull())
defaultDevice = new Graphic3d_WNTGraphicDevice();
return new V3d_Viewer(defaultDevice, aName);
#else
static Handle(Graphic3d_GraphicDevice) defaultDevice;
if (defaultDevice.IsNull())
defaultDevice = new Graphic3d_GraphicDevice("");
return new V3d_Viewer(defaultDevice, aName);
#endif //WNT
}
//===============================================================
// Function name: SetWindow
//===============================================================
void SampleDisplayAnimationPackage::SetWindow(const Handle(V3d_View)& aView,
const Standard_Integer hiwin,
const Standard_Integer lowin)
{
#ifdef WNT
Handle(Graphic3d_WNTGraphicDevice) d =
Handle(Graphic3d_WNTGraphicDevice)::DownCast(aView->Viewer()->Device());
Handle(WNT_Window) w = new WNT_Window(d,hiwin,lowin);
#else
Handle(Graphic3d_GraphicDevice) d =
Handle(Graphic3d_GraphicDevice)::DownCast(aView->Viewer()->Device());
Handle(Xw_Window) w = new Xw_Window(d,hiwin,lowin,Xw_WQ_3DQUALITY);
#endif
aView->SetWindow(w);
}
//===============================================================
// Function name: LoadData
//===============================================================
Standard_Boolean SampleDisplayAnimationPackage::LoadData(const Handle(AIS_InteractiveContext)& aContext,
const Standard_CString aPath)
{
myDeviation = 0.0008;
thread = 4;
myAngle = 0;
BRep_Builder B;
TopoDS_Shape CrankArm;
TopoDS_Shape CylinderHead;
TopoDS_Shape Propeller;
TopoDS_Shape Piston;
TopoDS_Shape EngineBlock;
TCollection_AsciiString aName;
aName = aPath; aName += "CrankArm.rle";
BRepTools::Read(CrankArm, aName.ToCString(), B);
aName = aPath; aName += "CylinderHead.rle";
BRepTools::Read(CylinderHead, aName.ToCString(), B);
aName = aPath; aName += "Propeller.rle";
BRepTools::Read(Propeller, aName.ToCString(), B);
aName = aPath; aName += "Piston.rle";
BRepTools::Read(Piston, aName.ToCString(), B);
aName = aPath; aName += "EngineBlock.rle";
BRepTools::Read(EngineBlock, aName.ToCString(), B);
if (CrankArm.IsNull() || CylinderHead.IsNull() || Propeller.IsNull() ||
Piston.IsNull() || EngineBlock.IsNull())
return Standard_False;
aContext->SetDeviationCoefficient(myDeviation);
myAISCylinderHead = new AIS_Shape(CylinderHead);
aContext->SetColor(myAISCylinderHead, Quantity_NOC_WHITE);
aContext->SetMaterial(myAISCylinderHead, Graphic3d_NOM_PLASTIC);
myAISEngineBlock = new AIS_Shape(EngineBlock);
aContext->SetColor(myAISEngineBlock, Quantity_NOC_WHITE);
aContext->SetMaterial(myAISEngineBlock, Graphic3d_NOM_PLASTIC);
aContext->Display(myAISCylinderHead, 1, -1, Standard_False, Standard_False);
aContext->Display(myAISEngineBlock, 1, -1, Standard_False, Standard_False);
myAISCrankArm = new AIS_Shape(CrankArm);
aContext->SetColor(myAISCrankArm, Quantity_NOC_HOTPINK);
aContext->SetMaterial(myAISCrankArm, Graphic3d_NOM_PLASTIC);
myAISPiston = new AIS_Shape(Piston);
aContext->SetColor(myAISPiston, Quantity_NOC_WHITE);
aContext->SetMaterial(myAISPiston, Graphic3d_NOM_PLASTIC);
myAISPropeller = new AIS_Shape(Propeller);
aContext->SetColor(myAISPropeller, Quantity_NOC_RED);
aContext->SetMaterial(myAISPropeller, Graphic3d_NOM_PLASTIC);
aContext->Display(myAISCrankArm, 1, -1, Standard_False, Standard_False);
aContext->Display(myAISPropeller, 1, -1, Standard_False, Standard_False);
aContext->Display(myAISPiston, 1, -1, Standard_True, Standard_False);
return Standard_True;
}
//===============================================================
// Function name: ChangePosition
//===============================================================
void SampleDisplayAnimationPackage::ChangePosition(const Handle(AIS_InteractiveContext)& aContext)
{
Standard_Real angleA;
Standard_Real angleB;
Standard_Real X;
gp_Ax1 ax1(gp_Pnt(0,0,0), gp_Vec(0,0,1));
myAngle++;
angleA = thread*myAngle*PI/180;
X = Sin(angleA)*3/8;
angleB = atan(X/Sqrt(-X*X+1));
Standard_Real decal(25*0.6);
// Build a transformation on the display
gp_Trsf aPropellerTrsf;
aPropellerTrsf.SetRotation(ax1, angleA);
aContext->SetLocation(myAISPropeller, aPropellerTrsf);
gp_Ax3 base(gp_Pnt(3*decal*(1-Cos(angleA)), -3*decal*Sin(angleA),0),
gp_Vec(0,0,1), gp_Vec(1,0,0));
gp_Trsf aCrankArmTrsf;
aCrankArmTrsf.SetTransformation(base.Rotated(gp_Ax1(gp_Pnt(3*decal,0,0), gp_Dir(0,0,1)), angleB));
aContext->SetLocation(myAISCrankArm, aCrankArmTrsf);
gp_Trsf aPistonTrsf;
aPistonTrsf.SetTranslation(gp_Vec(-3*decal*(1-Cos(angleA))-8*decal*(1-Cos(angleB)),0,0));
aContext->SetLocation(myAISPiston, aPistonTrsf);
aContext->UpdateCurrentViewer();
}
//===============================================================
// Function name: GetDeviationCoefficient
//===============================================================
Standard_Real SampleDisplayAnimationPackage::GetDeviationCoefficient()
{
return myDeviation;
}
//===============================================================
// Function name: SetDeviationCoefficient
//===============================================================
void SampleDisplayAnimationPackage::SetDeviationCoefficient(const Handle(AIS_InteractiveContext)& aContext,
const Standard_Real aValue)
{
myDeviation = aValue;
aContext->SetDeviationCoefficient(myDeviation);
TopoDS_Shape Propeller = myAISPropeller->Shape();
BRepTools::Clean(Propeller);
myAISPropeller->Set(Propeller);
aContext->Deactivate(myAISPropeller);
aContext->Redisplay(myAISPropeller);
}
//===============================================================
// Function name: GetAngleIncrement
//===============================================================
Standard_Integer SampleDisplayAnimationPackage::GetAngleIncrement()
{
return thread;
}
//===============================================================
// Function name: SetAngleIncrement
//===============================================================
void SampleDisplayAnimationPackage::SetAngleIncrement(const Standard_Integer aValue)
{
thread = aValue;
}
//===============================================================
// Function name: SaveImage
//===============================================================
#ifndef WNT
Standard_Boolean SampleDisplayAnimationPackage::SaveImage(const Standard_CString ,
const Standard_CString ,
const Handle(V3d_View)& )
{
#else
Standard_Boolean SampleDisplayAnimationPackage::SaveImage(const Standard_CString aFileName,
const Standard_CString aFormat,
const Handle(V3d_View)& aView)
{
Handle(Aspect_Window) anAspectWindow = aView->Window();
Handle(WNT_Window) aWNTWindow = Handle(WNT_Window)::DownCast(anAspectWindow);
if (aFormat == "bmp") aWNTWindow->SetOutputFormat(WNT_TOI_BMP);
if (aFormat == "gif") aWNTWindow->SetOutputFormat(WNT_TOI_GIF);
if (aFormat == "xwd") aWNTWindow->SetOutputFormat(WNT_TOI_XWD);
aWNTWindow->Dump(aFileName);
#endif
return Standard_True;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,347 @@
// File: SampleHLRPackage.cxx
// Created: Mon Mar 6 14:52:10 2000
// Author: UI team
// <ui@flox.nnov.matra-dtv.fr>
#include <SampleHLRPackage.hxx>
#include <Aspect_Window.hxx>
#include <V3d_Viewer.hxx>
#include <V3d_View.hxx>
#include <V2d_Viewer.hxx>
#include <V2d_View.hxx>
#include <AIS_InteractiveContext.hxx>
#include <ISession2D_InteractiveContext.hxx>
#include <AIS_Shape.hxx>
#include <AIS_Trihedron.hxx>
#include <ISession2D_Shape.hxx>
#include <Quantity_Color.hxx>
#include <Aspect_ColorMap.hxx>
#include <Aspect_GenericColorMap.hxx>
#include <Aspect_ColorMapEntry.hxx>
#include <Aspect_WidthMap.hxx>
#include <Aspect_WidthMapEntry.hxx>
#include <Aspect_TypeMap.hxx>
#include <Aspect_TypeMapEntry.hxx>
#include <Aspect_LineStyle.hxx>
#include <TColQuantity_Array1OfLength.hxx>
#include <Geom_Axis2Placement.hxx>
#include <gp.hxx>
#include <V3d_Coordinate.hxx>
#include <Prs3d_Projector.hxx>
#include <HLRAlgo_Projector.hxx>
#include <TopoDS_Shape.hxx>
#include <BRep_Builder.hxx>
#include <BRepTools.hxx>
#ifdef WNT
#include <WNT_Window.hxx>
#include <WNT_GraphicDevice.hxx>
#include <WNT_WDriver.hxx>
#include <Graphic3d_WNTGraphicDevice.hxx>
#else
#include <Xw_Window.hxx>
#include <Xw_GraphicDevice.hxx>
#include <Xw_Driver.hxx>
#include <Graphic3d_GraphicDevice.hxx>
#endif
/*----------------------------------------------------------------------*/
#ifdef WNT
static Handle(Graphic3d_WNTGraphicDevice) defaultDevice;
static Handle(WNT_GraphicDevice) default2dDevice;
#else
static Handle(Graphic3d_GraphicDevice) defaultDevice;
static Handle(Xw_GraphicDevice) default2dDevice;
#endif
Handle(AIS_Trihedron) myTrihedron;
Handle(ISession2D_Shape) myDisplayableShape;
//===============================================================
// Function name: CreateViewer3d
//===============================================================
Handle(V3d_Viewer) SampleHLRPackage::CreateViewer3d(const Standard_ExtString aName)
{
#ifdef WNT
if (defaultDevice.IsNull())
defaultDevice = new Graphic3d_WNTGraphicDevice();
return new V3d_Viewer(defaultDevice, aName);
#else
if (defaultDevice.IsNull())
defaultDevice = new Graphic3d_GraphicDevice("");
return new V3d_Viewer(defaultDevice, aName);
#endif //WNT
}
//===============================================================
// Function name: SetWindow3d
//===============================================================
void SampleHLRPackage::SetWindow3d (const Handle(V3d_View)& aView,
const Standard_Integer hiwin,
const Standard_Integer lowin)
{
#ifdef WNT
Handle(Graphic3d_WNTGraphicDevice) d =
Handle(Graphic3d_WNTGraphicDevice)::DownCast(aView->Viewer()->Device());
Handle(WNT_Window) w = new WNT_Window(d,hiwin,lowin);
#else
Handle(Graphic3d_GraphicDevice) d =
Handle(Graphic3d_GraphicDevice)::DownCast(aView->Viewer()->Device());
Handle(Xw_Window) w = new Xw_Window(d,hiwin,lowin,Xw_WQ_3DQUALITY);
#endif
aView->SetWindow(w);
}
//===============================================================
// Function name: CreateViewer2d
//===============================================================
Handle(V2d_Viewer) SampleHLRPackage::CreateViewer2d (const Standard_ExtString aName)
{
#ifdef WNT
if(default2dDevice.IsNull())
default2dDevice = new WNT_GraphicDevice();
#else
if(default2dDevice.IsNull())
default2dDevice = new Xw_GraphicDevice("",Xw_TOM_READONLY);
#endif
return new V2d_Viewer(default2dDevice,aName,"");
}
//===============================================================
// Function name: CreateView2d
//===============================================================
Handle(V2d_View) SampleHLRPackage::CreateView2d (const Handle(V2d_Viewer)& aViewer,
const Standard_Integer hiwin,
const Standard_Integer lowin)
{
#ifdef WNT
Handle(WNT_GraphicDevice) GD = Handle(WNT_GraphicDevice)::DownCast(aViewer->Device());
Handle(WNT_Window) W = new WNT_Window(GD,hiwin,lowin,Quantity_NOC_MATRAGRAY);
Handle(WNT_WDriver) D = new WNT_WDriver(W);
#else
Handle(Xw_GraphicDevice) GD = Handle(Xw_GraphicDevice)::DownCast(aViewer->Device());
Handle(Xw_Window) W = new Xw_Window(GD,hiwin,lowin,Xw_WQ_DRAWINGQUALITY,Quantity_NOC_MATRAGRAY);
Handle(Xw_Driver) D = new Xw_Driver(W);
#endif
Handle(V2d_View) V = new V2d_View(D,aViewer);
V->Update();
return V;
}
//===============================================================
// Function name: InitMaps
//===============================================================
void SampleHLRPackage::InitMaps(const Handle(V2d_Viewer)& aViewer)
{
// update the Maps :
// entries are reserve for utilisation :
// - 1 for Visible edges HighLighted
// - 2 for Visible edges
// - 3 for Hidden edges HighLighted
// - 4 for Hidden edges
Handle(Aspect_GenericColorMap) aColorMap = Handle(Aspect_GenericColorMap)::DownCast(aViewer->ColorMap());
if (!aColorMap.IsNull()) {
aColorMap->AddEntry(Aspect_ColorMapEntry (1,Quantity_Color(Quantity_NOC_RED ))); // in fact just update
aColorMap->AddEntry(Aspect_ColorMapEntry (2,Quantity_Color(Quantity_NOC_WHITE))); // in fact just update
aColorMap->AddEntry(Aspect_ColorMapEntry (3,Quantity_Color(Quantity_NOC_RED ))); // in fact just update
aColorMap->AddEntry(Aspect_ColorMapEntry (4,Quantity_Color(Quantity_NOC_BLUE1))); // in fact just update
aViewer->SetColorMap(aColorMap);
}
Handle(Aspect_WidthMap) aWidthMap = aViewer->WidthMap();
aWidthMap->AddEntry(Aspect_WidthMapEntry(1,0.8)); // in fact just update
aWidthMap->AddEntry(Aspect_WidthMapEntry(2,0.4)); // in fact just update
aWidthMap->AddEntry(Aspect_WidthMapEntry(3,0.6)); // in fact just update
aWidthMap->AddEntry(Aspect_WidthMapEntry(4,0.2)); // in fact just update
aViewer->SetWidthMap(aWidthMap);
Handle(Aspect_TypeMap) aTypeMap = aViewer->TypeMap();
aTypeMap->AddEntry(Aspect_TypeMapEntry(1,Aspect_LineStyle(Aspect_TOL_SOLID)));
aTypeMap->AddEntry(Aspect_TypeMapEntry(2,Aspect_LineStyle(Aspect_TOL_SOLID)));
TColQuantity_Array1OfLength anArray(1,2);
anArray(1) = 0.5; anArray(2) = 0.5;
aTypeMap->AddEntry(Aspect_TypeMapEntry(3,Aspect_LineStyle(anArray)));
aTypeMap->AddEntry(Aspect_TypeMapEntry(4,Aspect_LineStyle(anArray)));
aViewer->SetTypeMap(aTypeMap);
}
//===============================================================
// Function name: DisplayTrihedron
//===============================================================
void SampleHLRPackage::DisplayTrihedron(const Handle(AIS_InteractiveContext)& aContext)
{
Handle(Geom_Axis2Placement) aTrihedronAxis=new Geom_Axis2Placement(gp::XOY());
myTrihedron=new AIS_Trihedron(aTrihedronAxis);
aContext->Display(myTrihedron);
}
//===============================================================
// Function name: GetShapes
//===============================================================
Standard_Boolean SampleHLRPackage::GetShapes(const Handle(AIS_InteractiveContext)& aSrcContext,
const Handle(AIS_InteractiveContext)& aDestContext)
{
myDisplayableShape = new ISession2D_Shape();
aDestContext->EraseAll(Standard_False);
aDestContext->Display(myTrihedron);
Standard_Boolean OneOrMoreFound = Standard_False;
for (aSrcContext->InitCurrent();aSrcContext->MoreCurrent();aSrcContext->NextCurrent())
{
Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(aSrcContext->Current());
if (!anAISShape.IsNull())
{
OneOrMoreFound = Standard_True;
TopoDS_Shape aShape = anAISShape->Shape();
myDisplayableShape->Add(aShape);
aDestContext->Display(anAISShape);
}
}
return OneOrMoreFound;
}
//===============================================================
// Function name: Apply
//===============================================================
void SampleHLRPackage::Apply(const Handle(ISession2D_InteractiveContext)& aContext2d,
const Standard_Integer aDisplayMode)
{
aContext2d->EraseAll(Standard_False);
aContext2d->Display(myDisplayableShape, // object
aDisplayMode, // display mode
aDisplayMode, // selection mode
Standard_True); // Redraw
}
//===============================================================
// Function name: UpdateProjector
//===============================================================
void SampleHLRPackage::UpdateProjector(const Handle(V3d_View)& aView)
{
V3d_Coordinate DX,DY,DZ,XAt,YAt,ZAt, Vx,Vy,Vz ;
aView->Proj(DX,DY,DZ);
aView->At(XAt,YAt,ZAt);
aView->Up( Vx,Vy,Vz );
Standard_Boolean IsPerspective = (aView->Type() == V3d_PERSPECTIVE);
Quantity_Length aFocus = 1;
Prs3d_Projector aPrs3dProjector(IsPerspective,aFocus,DX,DY,DZ,XAt,YAt,ZAt,Vx,Vy,Vz);
HLRAlgo_Projector aProjector = aPrs3dProjector.Projector();
if (myDisplayableShape.IsNull()) return;
myDisplayableShape->SetProjector(aProjector);
}
//===============================================================
// Function name: SetNbIsos
//===============================================================
void SampleHLRPackage::SetNbIsos(const Standard_Integer aNbIsos)
{
myDisplayableShape->SetNbIsos(aNbIsos);
}
//===============================================================
// Function name: ReadBRep
//===============================================================
Standard_Boolean SampleHLRPackage::ReadBRep(const Standard_CString aFileName,
const Handle(AIS_InteractiveContext)& aContext)
{
TopoDS_Shape aShape;
BRep_Builder aBuilder;
Standard_Boolean result = BRepTools::Read(aShape,aFileName,aBuilder);
if (result)
aContext->Display(new AIS_Shape(aShape));
return result;
}
//===============================================================
// Function name: SaveBRep
//===============================================================
Standard_Boolean SampleHLRPackage::SaveBRep(const Standard_CString aFileName,
const Handle(AIS_InteractiveContext)& aContext)
{
TopoDS_Shape aShape;
Standard_Boolean isFound = Standard_False;
Handle(AIS_InteractiveObject) picked;
for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent()) {
picked = aContext->Current();
if (aContext->Current()->IsKind(STANDARD_TYPE(AIS_Shape))) {
aShape = Handle(AIS_Shape)::DownCast(picked)->Shape();
isFound = Standard_True;
break;
}
}
if (isFound) {
Standard_Boolean result = BRepTools::Write(aShape,aFileName);
return result;
}
return Standard_False;
}
//===============================================================
// Function name: SaveImage
//===============================================================
#ifndef WNT
Standard_Boolean SampleHLRPackage::SaveImage(const Standard_CString ,
const Standard_CString ,
const Handle(V3d_View)& )
{
#else
Standard_Boolean SampleHLRPackage::SaveImage(const Standard_CString aFileName,
const Standard_CString aFormat,
const Handle(V3d_View)& aView)
{
Handle(Aspect_Window) anAspectWindow = aView->Window();
Handle(WNT_Window) aWNTWindow = Handle(WNT_Window)::DownCast(anAspectWindow);
if (aFormat == "bmp") aWNTWindow->SetOutputFormat(WNT_TOI_BMP);
if (aFormat == "gif") aWNTWindow->SetOutputFormat(WNT_TOI_GIF);
if (aFormat == "xwd") aWNTWindow->SetOutputFormat(WNT_TOI_XWD);
aWNTWindow->Dump(aFileName);
#endif
return Standard_True;
}
//===============================================================
// Function name: SaveImage
//===============================================================
#ifndef WNT
Standard_Boolean SampleHLRPackage::SaveImage(const Standard_CString ,
const Standard_CString ,
const Handle(V2d_View)& )
{
#else
Standard_Boolean SampleHLRPackage::SaveImage(const Standard_CString aFileName,
const Standard_CString aFormat,
const Handle(V2d_View)& aView)
{
Handle(Aspect_Window) anAspectWindow = aView->Driver()->Window();
Handle(WNT_Window) aWNTWindow = Handle(WNT_Window)::DownCast(anAspectWindow);
if (aFormat == "bmp") aWNTWindow->SetOutputFormat(WNT_TOI_BMP);
if (aFormat == "gif") aWNTWindow->SetOutputFormat(WNT_TOI_GIF);
if (aFormat == "xwd") aWNTWindow->SetOutputFormat(WNT_TOI_XWD);
aWNTWindow->Dump(aFileName);
#endif
return Standard_True;
}

View File

@@ -0,0 +1,594 @@
// File: SampleImportExportPackage.cxx
// Created: Tue Nov 23 10:34:43 1999
// Author: UI team
// <ui@zamox.nnov.matra-dtv.fr>
#include <SampleImportExportPackage.ixx>
#include <AIS_InteractiveContext.hxx>
#include <AIS_InteractiveObject.hxx>
#include <AIS_Shape.hxx>
#include <TopoDS_Shape.hxx>
#include <TopTools_HSequenceOfShape.hxx>
#include <BRep_Builder.hxx>
#include <BRepTools.hxx>
#include <FSD_File.hxx>
#include <ShapeSchema.hxx>
#include <Storage_Data.hxx>
#include <Storage_HSeqOfRoot.hxx>
#include <Standard_Persistent.hxx>
#include <Storage_Root.hxx>
#include <PTopoDS_HShape.hxx>
#include <PTColStd_PersistentTransientMap.hxx>
#include <PTColStd_TransientPersistentMap.hxx>
#include <MgtBRep.hxx>
#include <Interface_Static.hxx>
#include <STEPControl_Controller.hxx>
#include <STEPControl_Reader.hxx>
#include <STEPControl_Writer.hxx>
#include <IGESControl_Controller.hxx>
#include <IGESControl_Reader.hxx>
#include <IGESControl_Writer.hxx>
#include <TopExp_Explorer.hxx>
#include <BRep_Tool.hxx>
#include <TopoDS.hxx>
#include <Geom_Curve.hxx>
#include <Geom_Surface.hxx>
#include <Geom_Plane.hxx>
#include <Geom_Line.hxx>
#include <TCollection_AsciiString.hxx>
#include <TCollection_ExtendedString.hxx>
#include <TColStd_SequenceOfAsciiString.hxx>
#include <TColStd_SequenceOfExtendedString.hxx>
#include <Aspect_Window.hxx>
#include <V3d_View.hxx>
#ifdef WNT
#include <WNT_Window.hxx>
#include <WNT_GraphicDevice.hxx>
#include <WNT_WDriver.hxx>
#include <Graphic3d_WNTGraphicDevice.hxx>
#else
#include <Xw_Window.hxx>
#include <Xw_GraphicDevice.hxx>
#include <Xw_Driver.hxx>
#include <Graphic3d_GraphicDevice.hxx>
#endif
/*----------------------------------------------------------------------*/
#ifdef WNT
static Handle(Graphic3d_WNTGraphicDevice) defaultDevice;
static Handle(WNT_GraphicDevice) default2dDevice;
#else
static Handle(Graphic3d_GraphicDevice) defaultDevice;
static Handle(Xw_GraphicDevice) default2dDevice;
#endif
//===============================================================
// Function name: CreateViewer3d
//===============================================================
Handle(V3d_Viewer) SampleImportExportPackage::CreateViewer3d(const Standard_ExtString aName)
{
#ifdef WNT
if (defaultDevice.IsNull())
defaultDevice = new Graphic3d_WNTGraphicDevice();
return new V3d_Viewer(defaultDevice, aName);
#else
if (defaultDevice.IsNull())
defaultDevice = new Graphic3d_GraphicDevice("");
return new V3d_Viewer(defaultDevice, aName);
#endif //WNT
}
//===============================================================
// Function name: SetWindow3d
//===============================================================
void SampleImportExportPackage::SetWindow3d (const Handle(V3d_View)& aView,
const Standard_Integer hiwin,
const Standard_Integer lowin)
{
#ifdef WNT
Handle(Graphic3d_WNTGraphicDevice) d =
Handle(Graphic3d_WNTGraphicDevice)::DownCast(aView->Viewer()->Device());
Handle(WNT_Window) w = new WNT_Window(d,hiwin,lowin);
#else
Handle(Graphic3d_GraphicDevice) d =
Handle(Graphic3d_GraphicDevice)::DownCast(aView->Viewer()->Device());
Handle(Xw_Window) w = new Xw_Window(d,hiwin,lowin,Xw_WQ_3DQUALITY);
#endif
aView->SetWindow(w);
}
/*----------------------------------------------------------------------*/
Handle(TopTools_HSequenceOfShape) BuildSequenceFromContext(const Handle(AIS_InteractiveContext)& aContext)
{
Handle(TopTools_HSequenceOfShape) aSequence = new TopTools_HSequenceOfShape();
Handle(AIS_InteractiveObject) picked;
for(aContext->InitCurrent();aContext->MoreCurrent();aContext->NextCurrent())
{
picked = aContext->Current();
if (aContext->Current()->IsKind(STANDARD_TYPE(AIS_Shape)))
{
TopoDS_Shape aShape = Handle(AIS_Shape)::DownCast(picked)->Shape();
aSequence->Append(aShape);
}
}
return aSequence;
}
//======================================================================
//= =
//= BREP =
//= =
//======================================================================
Standard_Boolean SampleImportExportPackage::ReadBREP(const Standard_CString aFileName,
const Handle(AIS_InteractiveContext)& aContext)
{
TopoDS_Shape aShape;
BRep_Builder aBuilder;
Standard_Boolean result = BRepTools::Read(aShape,aFileName,aBuilder);
if (result)
aContext->Display(new AIS_Shape(aShape));
return result;
}
Standard_Boolean SampleImportExportPackage::SaveBREP(const Standard_CString aFileName,
const Handle(AIS_InteractiveContext)& aContext)
{
Handle(TopTools_HSequenceOfShape) aSequence = BuildSequenceFromContext(aContext);
if (aSequence->Length() == 0)
return Standard_False;
TopoDS_Shape aShape = aSequence->Value(1);
Standard_Boolean result = BRepTools::Write(aShape,aFileName);
return result;
}
//======================================================================
//= =
//= CSFDB =
//= =
//======================================================================
TCollection_AsciiString BuildStorageErrorMessage (Storage_Error anError)
{
TCollection_AsciiString aMessage("Storage Status :");
switch ( anError )
{
case Storage_VSOk :
aMessage += "no problem \n";
break;
case Storage_VSOpenError :
aMessage += "OpenError while opening the stream \n";
break;
case Storage_VSModeError :
aMessage += "the stream is opened with a wrong mode for operation \n";
break;
case Storage_VSCloseError :
aMessage += "CloseError while closing the stream \n";
break;
case Storage_VSAlreadyOpen :
aMessage += "stream is already opened \n";
break;
case Storage_VSNotOpen :
aMessage += "stream not opened \n";
break;
case Storage_VSSectionNotFound :
aMessage += "the section is not found \n";
break;
case Storage_VSWriteError :
aMessage += "error during writing \n";
break;
case Storage_VSFormatError :
aMessage += "wrong format error occured while reading \n";
break;
case Storage_VSUnknownType :
aMessage += "try to read an unknown type \n";
break;
case Storage_VSTypeMismatch :
aMessage += "try to read a wrong primitive type (read a char while expecting a real) \n";
break;
case Storage_VSInternalError :
aMessage += "internal error \n ";
break;
case Storage_VSExtCharParityError :
aMessage += "problem with 16bit characters, may be an 8bit character is inserted inside a 16bit string \n";
break;
default :
aMessage += "Unknown Status ";
aMessage += anError;
aMessage += " \n";
break;
}
return aMessage;
}
Standard_Boolean SampleImportExportPackage::ReadCSFDB(const Standard_CString aFileName,
const Handle(AIS_InteractiveContext)& aContext,
TCollection_AsciiString& ReturnMessage)
{
Handle(TopTools_HSequenceOfShape) aSequence = new TopTools_HSequenceOfShape();
Standard_Integer i;
// an I/O driver
FSD_File f;
// the applicative Schema
Handle(ShapeSchema) s = new ShapeSchema;
// a Read/Write data object
Handle(Storage_Data) d = new Storage_Data;
d->ClearErrorStatus();
// Check file type
if (FSD_File::IsGoodFileType(aFileName) != Storage_VSOk) {
ReturnMessage = "Bad file type for ";
ReturnMessage += aFileName;
ReturnMessage += " \n";
return Standard_False;
}
// Open the archive, Read mode
Storage_Error err = f.Open(aFileName, Storage_VSRead);
// Read all the persistent object in the file with the schema
if ( err != Storage_VSOk ) {
ReturnMessage += BuildStorageErrorMessage(d->ErrorStatus());
return Standard_False;
}
d = s->Read( f );
err = d->ErrorStatus() ;
if ( err != Storage_VSOk ) {
ReturnMessage += BuildStorageErrorMessage(d->ErrorStatus());
return Standard_False;
}
// Close the file driver
f.Close();
ReturnMessage += "Application Name :"; ReturnMessage += d->ApplicationName();ReturnMessage += "\n";
ReturnMessage += "Application Version :"; ReturnMessage += d->ApplicationVersion();ReturnMessage += "\n";
ReturnMessage += "Data type :"; ReturnMessage += d->DataType();ReturnMessage += "\n";
ReturnMessage += "== User Infos : ==\n";
const TColStd_SequenceOfAsciiString& UserInfo = d->UserInfo();
for (i=1; i<=UserInfo.Length(); i++)
{ReturnMessage += UserInfo(i);ReturnMessage += "\n";}
ReturnMessage += "== Comments : ==\n";
const TColStd_SequenceOfExtendedString& Comments=d->Comments();
for (i=1; i<=Comments.Length(); i++)
{ReturnMessage += Comments(i);ReturnMessage += "\n";}
ReturnMessage += "----------------\n";
// Read all the root objects
// Get the root list
Handle(Storage_HSeqOfRoot) roots = d->Roots();
Handle(Standard_Persistent) p;
Handle(Storage_Root) r;
Handle(PTopoDS_HShape) aPShape;
for (i = 1; i <= roots->Length(); i++ )
{
// Get the root
r = roots->Value(i);
// Get the persistent application object from the root
p = r->Object();
// Display information
ReturnMessage += "Persistent Object "; ReturnMessage += i; ReturnMessage += "\n";
ReturnMessage += "Name :"; ReturnMessage += r->Name(); ReturnMessage += "\n";
ReturnMessage += "Type :"; ReturnMessage += r->Type(); ReturnMessage += "\n";
aPShape = Handle(PTopoDS_HShape)::DownCast(p);
if (!aPShape.IsNull())
{
// To Be ReWriten to suppress the cout,
// and provide a CallBack method for dynamic information.
// Get the persistent shape
PTColStd_PersistentTransientMap aMap;
TopoDS_Shape aTShape;
MgtBRep::Translate(aPShape,aMap,aTShape,
MgtBRep_WithTriangle);
aSequence->Append(aTShape);
}
else
{
ReturnMessage += "Error -> Unable to read\n";
}
}
// Display shapes
for(i=1; i<=aSequence->Length(); i++)
aContext->Display(new AIS_Shape(aSequence->Value(i)));
return Standard_True;
}
Standard_Boolean SampleImportExportPackage::SaveCSFDB(const Standard_CString aFileName,
const Handle(AIS_InteractiveContext)& aContext,
TCollection_AsciiString& ReturnMessage,
const MgtBRep_TriangleMode aTriangleMode)
{
Handle(TopTools_HSequenceOfShape) aHSequenceOfShape = BuildSequenceFromContext(aContext);
Standard_Integer ReturnValue = Standard_True;
if (aHSequenceOfShape->Length() == 0)
return Standard_False;
// an I/O driver
FSD_File f;
// the applicative Schema containing
// Pesistent Topology and Geometry
Handle(ShapeSchema) s = new ShapeSchema;
// a Read/Write data object
Handle(Storage_Data) d = new Storage_Data;
d->ClearErrorStatus();
// To Be ReWriten to suppress the Strings,
// and provide a CallBack method for dynamic information.
d->SetApplicationName(TCollection_ExtendedString("SampleImportExport"));
d->SetApplicationVersion("1");
d->SetDataType(TCollection_ExtendedString("Shapes"));
d->AddToUserInfo("Try to store a Persistent set of Shapes in a flat file");
d->AddToComments(TCollection_ExtendedString("application is based on CasCade 2.0"));
// Open the archive, Write mode
Storage_Error err = f.Open(aFileName, Storage_VSWrite);
if ( err != Storage_VSOk ) {
ReturnMessage += BuildStorageErrorMessage(err);
return Standard_False;
}
PTColStd_TransientPersistentMap aMap;
ReturnMessage += "The Object have be saved in the file ";
ReturnMessage += aFileName;
ReturnMessage += "\n with the names : ";
for (Standard_Integer i=1;i<=aHSequenceOfShape->Length();i++)
{
TopoDS_Shape aTShape= aHSequenceOfShape->Value(i);
TCollection_AsciiString anObjectName("anObjectName_");
anObjectName += i;
ReturnMessage += anObjectName;
ReturnMessage += " \n";
if ( aTShape.IsNull() )
{
ReturnMessage += " Error : Invalid shape \n";
ReturnValue = Standard_False;
continue;
}
//Create the persistent Shape
Handle(PTopoDS_HShape) aPShape =
MgtBRep::Translate(aTShape, aMap, aTriangleMode);
// Add the object in the data structure as root
// To Be ReWriten to suppress the cout,
// and provide a CallBack method for dynamic information.
d->AddRoot(anObjectName, aPShape);
}
// Write the object in the file with the schema
s->Write( f, d);
// Close the driver
f.Close();
if ( d->ErrorStatus() != Storage_VSOk )
{
ReturnMessage += BuildStorageErrorMessage(d->ErrorStatus());
return Standard_False;
}
return ReturnValue;
}
//======================================================================
//= =
//= STEP =
//= =
//======================================================================
IFSelect_ReturnStatus SampleImportExportPackage::ReadSTEP(const Standard_CString aFileName,
const Handle(AIS_InteractiveContext)& aContext)
{
Handle(TopTools_HSequenceOfShape) aSequence = new TopTools_HSequenceOfShape();
TopoDS_Shape aShape;
STEPControl_Controller::Init();
STEPControl_Reader aReader;
IFSelect_ReturnStatus status = aReader.ReadFile(aFileName);
if (status == IFSelect_RetDone)
{
Standard_Boolean failsonly = Standard_False;
aReader.PrintCheckLoad (failsonly, IFSelect_ItemsByEntity);
// Root transfers
Standard_Integer nbr = aReader.NbRootsForTransfer();
aReader.PrintCheckTransfer (failsonly, IFSelect_ItemsByEntity);
for ( Standard_Integer n = 1; n<= nbr; n++)
{
aReader.TransferRoot(n);
// Collecting resulting entities
Standard_Integer nbs = aReader.NbShapes();
if (nbs == 0)
{
aSequence.Nullify();
return IFSelect_RetVoid;
}
else
{
for (Standard_Integer i =1; i<=nbs; i++)
{
aShape=aReader.Shape(i);
aSequence->Append(aShape);
}
}
}
}
else
{
aSequence.Nullify();
}
// Display shapes
if (!aSequence.IsNull()) {
for(int i=1;i<= aSequence->Length();i++)
aContext->Display(new AIS_Shape(aSequence->Value(i)));
}
return status;
}
Standard_Boolean TestFacetedBrep(const Handle(TopTools_HSequenceOfShape)& aHSequenceOfShape)
{
Standard_Boolean OneErrorFound = Standard_False;
for (Standard_Integer i=1;i<=aHSequenceOfShape->Length();i++)
{
TopoDS_Shape aShape= aHSequenceOfShape->Value(i);
TopExp_Explorer Ex(aShape,TopAbs_FACE);
while (Ex.More() && !OneErrorFound)
{
// Get the Geom_Surface outside the TopoDS_Face
Handle(Geom_Surface) aSurface = BRep_Tool::Surface(TopoDS::Face(Ex.Current()));
// check if it is a plane.
if (!aSurface->IsKind(STANDARD_TYPE(Geom_Plane)))
OneErrorFound=Standard_True;
Ex.Next();
}
TopExp_Explorer Ex2(aShape,TopAbs_EDGE);
while (Ex2.More() && !OneErrorFound)
{
// Get the Geom_Curve outside the TopoDS_Face
Standard_Real FirstDummy,LastDummy;
Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(Ex2.Current()),FirstDummy,LastDummy);
// check if it is a line.
if (!aCurve->IsKind(STANDARD_TYPE(Geom_Line)))
OneErrorFound=Standard_True;
Ex2.Next();
}
}
return !OneErrorFound;
}
IFSelect_ReturnStatus SampleImportExportPackage::SaveSTEP(const Standard_CString aFileName,
const Handle(AIS_InteractiveContext)& aContext,
const STEPControl_StepModelType aValue)
{
Handle(TopTools_HSequenceOfShape) aHSequenceOfShape = BuildSequenceFromContext(aContext);
if (aHSequenceOfShape->Length() == 0)
return IFSelect_RetError;
if (aValue == STEPControl_FacetedBrep)
if (!TestFacetedBrep(aHSequenceOfShape))
return IFSelect_RetError;
// CREATE THE WRITER
STEPControl_Writer aWriter;
IFSelect_ReturnStatus status;
for (Standard_Integer i=1;i<=aHSequenceOfShape->Length();i++)
{
status = aWriter.Transfer(aHSequenceOfShape->Value(i), aValue);
if ( status != IFSelect_RetDone ) return status;
}
status = aWriter.Write(aFileName);
return status;
}
//======================================================================
//= =
//= IGES =
//= =
//======================================================================
Standard_Integer SampleImportExportPackage::ReadIGES(const Standard_CString aFileName,
const Handle(AIS_InteractiveContext)& aContext)
{
Handle(TopTools_HSequenceOfShape) aSequence = new TopTools_HSequenceOfShape();
IGESControl_Reader Reader;
Standard_Integer status = Reader.ReadFile(aFileName);
if (status != IFSelect_RetDone) return status;
Reader.TransferRoots();
TopoDS_Shape aShape = Reader.OneShape();
aSequence->Append(aShape);
// Display shapes
for(int i=1;i<= aSequence->Length();i++)
aContext->Display(new AIS_Shape(aSequence->Value(i)));
return status;
}
Standard_Boolean SampleImportExportPackage::SaveIGES(const Standard_CString aFileName,
const Handle(AIS_InteractiveContext)& aContext)
{
Handle(TopTools_HSequenceOfShape) aHSequenceOfShape = BuildSequenceFromContext(aContext);
if (aHSequenceOfShape->Length() == 0)
return Standard_False;
IGESControl_Controller::Init();
IGESControl_Writer ICW (Interface_Static::CVal("XSTEP.iges.unit"),
Interface_Static::IVal("XSTEP.iges.writebrep.mode"));
for (Standard_Integer i=1;i<=aHSequenceOfShape->Length();i++)
ICW.AddShape (aHSequenceOfShape->Value(i));
ICW.ComputeModel();
Standard_Boolean result = ICW.Write(aFileName);
return result;
}
//===============================================================
// Function name: SaveImage
//===============================================================
#ifndef WNT
Standard_Boolean SampleImportExportPackage::SaveImage(const Standard_CString ,
const Standard_CString ,
const Handle(V3d_View)& ) {
#else
Standard_Boolean SampleImportExportPackage::SaveImage(const Standard_CString aFileName,
const Standard_CString aFormat,
const Handle(V3d_View)& aView)
{
Handle(Aspect_Window) anAspectWindow = aView->Window();
Handle(WNT_Window) aWNTWindow = Handle(WNT_Window)::DownCast(anAspectWindow);
if (aFormat == "bmp") aWNTWindow->SetOutputFormat(WNT_TOI_BMP);
if (aFormat == "gif") aWNTWindow->SetOutputFormat(WNT_TOI_GIF);
if (aFormat == "xwd") aWNTWindow->SetOutputFormat(WNT_TOI_XWD);
aWNTWindow->Dump(aFileName);
#endif
return Standard_True;
}

View File

@@ -0,0 +1,291 @@
// File: CASCADEView2d.cxx
// Created: Wed Jul 18 11:11:22 2001
// Author:
// <avo@TIREX>
#ifdef WNT
# include <windows.h>
#endif
#include <Standard_Stream.hxx>
#include <jawt_md.h>
#include <CASCADEView2d.hxx>
#include <jcas.hxx>
#include <V2d_View.hxx>
#include <V2d_Viewer.hxx>
#ifdef WNT
# include <WNT_Window.hxx>
#include <WNT_WDriver.hxx>
// # include <Graphic2d_WNTGraphicDevice.hxx>
# include <OpenGl_GraphicDriver.hxx>
#else
# include <Xw_Window.hxx>
# include <Xw_Driver.hxx>
// # include <Graphic2d_GraphicDevice.hxx>
#endif // WNT
/*
* Class: CASCADEView2d
* Method: paint
* Signature: (Ljava/awt/Graphics;)V
*/
JNIEXPORT void JNICALL Java_CASCADEView2d_paint(JNIEnv *env, jobject theCanvas, jobject theGraphics) {
// cout << "Info: -------------------------- Java_CASCADEView2d_paint ("<< theCanvas <<") ----------------------" << endl;
jclass jViewPort2dClass = env->FindClass("CASCADEView2d");
if(!jViewPort2dClass){ jcas_ThrowException(env, "cant find canvas class"); return; }
jfieldID jIsWindowID = env->GetFieldID(jViewPort2dClass, "hasWindow", "Z");
if(!jIsWindowID){ jcas_ThrowException(env, "cant find the boolean field id"); return; }
jboolean jIsWindow = env->GetBooleanField(theCanvas, jIsWindowID);
Handle(V2d_View) theView;
Handle(V2d_Viewer) theViewer;
if(!jIsWindow){
// get the window view and viewer
// cout << "Info: First time, init VIEW." << endl;
jfieldID jViewerID = env->GetFieldID(jViewPort2dClass, "myViewer", "LCASCADESamplesJni/V2d_Viewer;");
if(!jViewerID) { jcas_ThrowException(env, "cant find the view field id");return; }
jobject jViewer = env->GetObjectField(theCanvas, jViewerID);
if(!jViewer) { // viewer and view are not created, create them now.
jcas_ThrowException(env, "No jViewer in first paint\n");
return;
}else {
void *ptrViewer = jcas_GetHandle(env, jViewer);
if (ptrViewer != NULL) {
theViewer = *((Handle(V2d_Viewer)*)ptrViewer);
}else{
cout << "Error: cant get V2d_Viewer from canvas field" << endl;
}
}
// start paste
if (!theViewer.IsNull()){
// get drawing surface
//-----------------------------------------------
JAWT awt;
JAWT_DrawingSurface* ds;
JAWT_DrawingSurfaceInfo* dsi;
#ifdef WNT
JAWT_Win32DrawingSurfaceInfo* dsi_win;
#else
JAWT_X11DrawingSurfaceInfo* dsi_x11;
#endif //WNT
jboolean result;
jint lock;
// Get the AWT
awt.version = JAWT_VERSION_1_3;
result = JAWT_GetAWT(env, &awt);
if (result == JNI_FALSE)
{
cout << "AWT not found" << endl;
jcas_ThrowException(env, "AWT not found\n");
// alock.Release();
return;
}
// Get the drawing surface
ds = awt.GetDrawingSurface(env, theCanvas);
if (ds == NULL)
{
cout << "NULL drawing surface" << endl;
jcas_ThrowException(env, "NULL drawing surface\n");
return;
}
// Lock the drawing surface
lock = ds->Lock(ds);
if ((lock & JAWT_LOCK_ERROR) != 0)
{
cout << "Error locking surface" << endl;
jcas_ThrowException(env, "Error locking surface\n");
awt.FreeDrawingSurface(ds);
return;
}
// Get the drawing surface info
dsi = ds->GetDrawingSurfaceInfo(ds);
if (dsi == NULL)
{
cout << "Error getting surface info" << endl;
jcas_ThrowException(env, "Error getting surface info\n");
ds->Unlock(ds);
awt.FreeDrawingSurface(ds);
// alock.Release();
return;
}
// Get the platform-specific drawing info
Aspect_Handle theWindow;
#ifdef WNT
dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
theWindow = dsi_win->hwnd;
#else
dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
theWindow = dsi_x11->drawable;
#endif
// if (jIsWindow == JNI_FALSE)
// {
#ifdef WNT
long wd = GetWindowLong (( HWND )theWindow, GWL_USERDATA);
long wProc = GetWindowLong (( HWND )theWindow, GWL_WNDPROC);
#endif
// get params to build view
jfieldID jBackColorID = env->GetFieldID(jViewPort2dClass, "myBackColor", "S");
jshort jBackColor = env->GetShortField(theCanvas, jBackColorID);
#ifdef WNT
Handle(WNT_Window) w = new WNT_Window(Handle(WNT_GraphicDevice)::DownCast(theViewer->Device()),theWindow, (Quantity_NameOfColor) jBackColor);
Handle(WNT_WDriver) d = new WNT_WDriver(w);
#else
Handle(Xw_Window) w = new Xw_Window(Handle(Xw_GraphicDevice)::DownCast(theViewer->Device()),theWindow,Xw_WQ_DRAWINGQUALITY, (Quantity_NameOfColor) jBackColor);
Handle(Xw_Driver) d = new Xw_Driver(w);
#endif
theView = new V2d_View(d, theViewer);
theView->Update();
#ifdef WNT
long wd1 = SetWindowLong ((HWND) theWindow, GWL_USERDATA, wd);
long wProc1 = SetWindowLong ((HWND) theWindow, GWL_WNDPROC, wProc);
#endif
cout << "Info: Set hasWindow = TRUE : id == " << jIsWindowID << endl;
jIsWindow = JNI_TRUE;
// }
env->SetBooleanField(theCanvas, jIsWindowID, jIsWindow);
/******************************
fill fields with VIEWER ONLY
*******************************/
Handle(V2d_View)* theViewPtr = new Handle(V2d_View);
*theViewPtr = theView;
jobject aJavaView = jcas_CreateObject(env,"CASCADESamplesJni/V2d_View", theViewPtr);
jfieldID jViewID = env->GetFieldID(jViewPort2dClass, "myView", "LCASCADESamplesJni/V2d_View;");
env->SetObjectField(theCanvas, jViewID, aJavaView);
// assume that viewer has been already created.
// Handle(V2d_Viewer)* theViewerPtr = new Handle(V2d_Viewer);
// *theViewerPtr = theViewer;
// jfieldID jViewerID = env->GetFieldID(jViewPort2dClass, "myViewer", "LCASCADESamplesJni/V2d_Viewer;");
// jobject aJavaViewer = jcas_CreateObject(env,"CASCADESamplesJni/V2d_Viewer", theViewerPtr);
// env->SetObjectField(theCanvas, jViewerID, aJavaViewer);
// Free the AWT
//-----------------------------------------------
// Free the drawing surface info
ds->FreeDrawingSurfaceInfo(dsi);
// Unlock the drawing surface
ds->Unlock(ds);
// Free the drawing surface
awt.FreeDrawingSurface(ds);
}else{
cout << "Error: Cant obtain V2d_Viewer" << endl;
}
/////////////////////////// end paste
// cout << "Info: Init viewer done" << endl;
} // end !hasWindow.
// get stored view field
jfieldID jViewID = env->GetFieldID(jViewPort2dClass, "myView", "LCASCADESamplesJni/V2d_View;");
jobject jView = env->GetObjectField(theCanvas, jViewID);
if(!jView){
jcas_ThrowException(env, "Error getting viewer while has window ?\n");
return;
}
void *ptrView = jcas_GetHandle(env, jView);
if (ptrView != NULL)
theView = *((Handle(V2d_View)*)ptrView);
// paint routine.
if(theView.IsNull()){
jcas_ThrowException(env, "Error getting V2d_View ?\n");
return;
}
JAWT awt;
JAWT_DrawingSurface* ds;
jboolean result;
jint lock;
// Get the AWT
awt.version = JAWT_VERSION_1_3;
result = JAWT_GetAWT(env, &awt);
if (result == JNI_FALSE)
{
cout << "AWT not found" << endl;
jcas_ThrowException(env, "AWT not found\n");
// alock.Release();
return;
}
// Get the drawing surface
ds = awt.GetDrawingSurface(env, theCanvas);
if (ds == NULL)
{
cout << "NULL drawing surface" << endl;
jcas_ThrowException(env, "NULL drawing surface\n");
// alock.Release();
return;
}
// Lock the drawing surface
lock = ds->Lock(ds);
// cout << "Result of locking is " << lock << endl;
if ((lock & JAWT_LOCK_ERROR) != 0)
{
cout << "Error locking surface" << endl;
jcas_ThrowException(env, "Error locking surface\n");
awt.FreeDrawingSurface(ds);
// alock.Release();
return;
}
// Redraw V2d_View after locking AWT drawing surface
// theView->Redraw(); // 3d
jfieldID jNeedResizeID = env->GetFieldID(jViewPort2dClass, "needResize", "Z");
if(!jNeedResizeID){
ds->Unlock(ds);
awt.FreeDrawingSurface(ds);
jcas_ThrowException(env, "cant find the needREsize field id");
return;
}
jboolean jNeedResize = env->GetBooleanField(theCanvas, jNeedResizeID);
if(jNeedResize == JNI_TRUE){
// cout << "Info: bef update, need resize." << endl;
theView->MustBeResized(V2d_TOWRE_ENLARGE_OBJECTS);
jNeedResize = JNI_FALSE;
env->SetBooleanField(theCanvas, jNeedResizeID, jNeedResize);
}
theView->Update();
ds->Unlock(ds);
// Free the drawing surface
awt.FreeDrawingSurface(ds);
}

View File

@@ -0,0 +1,294 @@
// File: CASCADEView3d.cxx
// Created: Wed Jul 18 11:11:22 2001
// Author:
// <avo@TIREX>
#ifdef WNT
# include <windows.h>
#endif
#include <Standard_Stream.hxx>
#include <jawt_md.h>
#include <CASCADEView3d.hxx>
#include <jcas.hxx>
#include <V3d_View.hxx>
#ifdef WNT
# include <WNT_Window.hxx>
# include <Graphic3d_WNTGraphicDevice.hxx>
#else
# include <Xw_Window.hxx>
# include <Graphic3d_GraphicDevice.hxx>
#endif // WNT
#define RETURN_ERROR(msg) {cout << "Error: '"<< msg <<"'" << endl;return;}
// #include "Aspect_Handle.hxx>
/*
* Class: CASCADEView3d
* Method: paint
* Signature: (Ljava/awt/Graphics;)V
*/
JNIEXPORT void JNICALL Java_CASCADEView3d_paint (JNIEnv *env, jobject theCanvas, jobject theGraphics){
// cout << "Info: -------------------------- Java_CASCADEView3d_paint ----------------------" << endl;
jclass jViewPort3dClass = env->FindClass("CASCADEView3d");
if(!jViewPort3dClass)RETURN_ERROR("cant find canvas class");
jfieldID jIsWindowID = env->GetFieldID(jViewPort3dClass, "hasWindow", "Z");
if(!jIsWindowID)RETURN_ERROR("cant find the boolean field id");
jboolean jIsWindow = env->GetBooleanField(theCanvas, jIsWindowID);
Handle(V3d_View) theView;
Handle(V3d_Viewer) theViewer;
if(!jIsWindow){
// get the window view and viewer
// cout << "Info: First time, init fields." << endl;
jfieldID jViewID = env->GetFieldID(jViewPort3dClass, "myView", "LCASCADESamplesJni/V3d_View;");
if(!jViewID) RETURN_ERROR("cant find the view field id");
jobject jView = env->GetObjectField(theCanvas, jViewID);
if(!jView) { // viewer and view are not created, create them now.
Standard_ExtString aViewerName = TCollection_ExtendedString ("V3d_Viewer in SimpleViewer").ToExtString();
#ifdef WNT
static Handle(Graphic3d_WNTGraphicDevice) defaultDevice;
if (defaultDevice.IsNull())
defaultDevice = new Graphic3d_WNTGraphicDevice();
theViewer = new V3d_Viewer(defaultDevice, aViewerName);
#else
static Handle(Graphic3d_GraphicDevice) defaultDevice;
if (defaultDevice.IsNull())
defaultDevice = new Graphic3d_GraphicDevice("");
theViewer = new V3d_Viewer(defaultDevice, aViewerName);
#endif //WNT
theView = theViewer->CreateView();
// store the values into the fields
}else {
void *ptrView = jcas_GetHandle(env, jView);
if (ptrView != NULL) {
theView = *((Handle(V3d_View)*)ptrView);
}else{
cout << "Error: cant get V3d_View from canvas field" << endl;
}
}
// start paste
if (!theView.IsNull()){
// get drawing surface
//-----------------------------------------------
JAWT awt;
JAWT_DrawingSurface* ds;
JAWT_DrawingSurfaceInfo* dsi;
#ifdef WNT
JAWT_Win32DrawingSurfaceInfo* dsi_win;
#else
JAWT_X11DrawingSurfaceInfo* dsi_x11;
#endif //WNT
jboolean result;
jint lock;
// Get the AWT
awt.version = JAWT_VERSION_1_3;
result = JAWT_GetAWT(env, &awt);
if (result == JNI_FALSE)
{
cout << "AWT not found" << endl;
jcas_ThrowException(env, "AWT not found\n");
// alock.Release();
return;
}
// Get the drawing surface
ds = awt.GetDrawingSurface(env, theCanvas);
if (ds == NULL)
{
cout << "NULL drawing surface" << endl;
jcas_ThrowException(env, "NULL drawing surface\n");
return;
}
// Lock the drawing surface
lock = ds->Lock(ds);
if ((lock & JAWT_LOCK_ERROR) != 0)
{
cout << "Error locking surface" << endl;
jcas_ThrowException(env, "Error locking surface\n");
awt.FreeDrawingSurface(ds);
return;
}
// Get the drawing surface info
dsi = ds->GetDrawingSurfaceInfo(ds);
if (dsi == NULL)
{
cout << "Error getting surface info" << endl;
jcas_ThrowException(env, "Error getting surface info\n");
ds->Unlock(ds);
awt.FreeDrawingSurface(ds);
// alock.Release();
return;
}
// Get the platform-specific drawing info
Aspect_Handle theWindow;
#ifdef WNT
dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
theWindow = dsi_win->hwnd;
#else
dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
theWindow = dsi_x11->drawable;
#endif
if (jIsWindow == JNI_FALSE)
{
#ifdef WNT
long wd = GetWindowLong (( HWND )theWindow, GWL_USERDATA);
long wProc = GetWindowLong (( HWND )theWindow, GWL_WNDPROC);
#endif
#ifdef WNT
Handle(WNT_Window) w = new WNT_Window(Handle(Graphic3d_WNTGraphicDevice)::DownCast(theView->Viewer()->Device()),theWindow);
#else
Handle(Xw_Window) w = new Xw_Window(Handle(Graphic3d_GraphicDevice)::DownCast(theView->Viewer()->Device()),theWindow,Xw_WQ_SAMEQUALITY);
#endif
// cout << "Info: Finally, set window:" << endl;
theView->SetWindow(w);
// cout << "Info: set window done" << endl;
#ifdef WNT
long wd1 = SetWindowLong ((HWND) theWindow, GWL_USERDATA, wd);
long wProc1 = SetWindowLong ((HWND) theWindow, GWL_WNDPROC, wProc);
#endif
jIsWindow = JNI_TRUE;
}
env->SetBooleanField(theCanvas, jIsWindowID, jIsWindow);
// jobject jView = env->GetObjectField(theCanvas, jViewID);
// jobject jNewView = ;
// env->SetObjectField(theCanvas, jViewID, jNewView); // remember V3d_View
/******************************
fill fields with viewer and viev
*******************************/
// jclass testClass = env->FindClass("CASCADESamplesJni/V2d_Viewer");
// cout << "Info: V3d fil lthe fields : get V2d_Viewer class : "<<testClass << endl;
Handle(V3d_View)* theViewPtr = new Handle(V3d_View);
*theViewPtr = theView;
jobject aJavaView = jcas_CreateObject(env,"CASCADESamplesJni/V3d_View", theViewPtr);
env->SetObjectField(theCanvas, jViewID, aJavaView);
Handle(V3d_Viewer)* theViewerPtr = new Handle(V3d_Viewer);
*theViewerPtr = theViewer;
jfieldID jViewerID = env->GetFieldID(jViewPort3dClass, "myViewer", "LCASCADESamplesJni/V3d_Viewer;");
jobject aJavaViewer = jcas_CreateObject(env,"CASCADESamplesJni/V3d_Viewer", theViewerPtr);
env->SetObjectField(theCanvas, jViewerID, aJavaViewer);
// fill the myView and myViewer fields.
// Free the AWT
//-----------------------------------------------
// Free the drawing surface info
ds->FreeDrawingSurfaceInfo(dsi);
// Unlock the drawing surface
ds->Unlock(ds);
// Free the drawing surface
awt.FreeDrawingSurface(ds);
}else{
cout << "Error: Cant obtain V3d_View" << endl;
}
/////////////////////////// end paste
// cout << "Info: Init viewer done" << endl;
} // end !hasWindow.
// get stored view field
jfieldID jViewID = env->GetFieldID(jViewPort3dClass, "myView", "LCASCADESamplesJni/V3d_View;");
jobject jView = env->GetObjectField(theCanvas, jViewID);
if(!jView){
jcas_ThrowException(env, "Error getting viewer while has window ?\n");
return;
}
void *ptrView = jcas_GetHandle(env, jView);
if (ptrView != NULL)
theView = *((Handle(V3d_View)*)ptrView);
// paint routine.
if(theView.IsNull()){
jcas_ThrowException(env, "Error getting V3d_View ?\n");
return;
}
JAWT awt;
JAWT_DrawingSurface* ds;
jboolean result;
jint lock;
// Get the AWT
awt.version = JAWT_VERSION_1_3;
result = JAWT_GetAWT(env, &awt);
if (result == JNI_FALSE)
{
cout << "AWT not found" << endl;
jcas_ThrowException(env, "AWT not found\n");
// alock.Release();
return;
}
// Get the drawing surface
ds = awt.GetDrawingSurface(env, theCanvas);
if (ds == NULL)
{
cout << "NULL drawing surface" << endl;
jcas_ThrowException(env, "NULL drawing surface\n");
// alock.Release();
return;
}
// Lock the drawing surface
lock = ds->Lock(ds);
// cout << "Result of locking is " << lock << endl;
if ((lock & JAWT_LOCK_ERROR) != 0)
{
cout << "Error locking surface" << endl;
jcas_ThrowException(env, "Error locking surface\n");
awt.FreeDrawingSurface(ds);
// alock.Release();
return;
}
// Redraw V3d_View after locking AWT drawing surface
// cout << " CASCADEView3d.cxx: redraw "<<endl;
jfieldID jNeedResizeID = env->GetFieldID(jViewPort3dClass, "needResize", "Z");
if(!jNeedResizeID){
ds->Unlock(ds);
awt.FreeDrawingSurface(ds);
jcas_ThrowException(env, "cant find the needREsize field id");
return;
}
jboolean jNeedResize = env->GetBooleanField(theCanvas, jNeedResizeID);
if(jNeedResize == JNI_TRUE){
// cout << "Info: bef update, need resize." << endl;
theView->MustBeResized();
jNeedResize = JNI_FALSE;
env->SetBooleanField(theCanvas, jNeedResizeID, jNeedResize);
}
theView->Redraw();
ds->Unlock(ds);
// Free the drawing surface
awt.FreeDrawingSurface(ds);
}

View File

@@ -0,0 +1,817 @@
#include <SampleViewer3DPackage.hxx>
#include <AIS_InteractiveContext.hxx>
#include <AIS_Shape.hxx>
#include <TCollection_AsciiString.hxx>
#include <V3d_Viewer.hxx>
#include <V3d_View.hxx>
#include <V3d_Coordinate.hxx>
#include <V3d_AmbientLight.hxx>
#include <V3d_SpotLight.hxx>
#include <V3d_PositionalLight.hxx>
#include <V3d_DirectionalLight.hxx>
#include <V3d_Plane.hxx>
#include <gp_Pnt.hxx>
#include <gp_Pln.hxx>
#include <gp_Pnt2d.hxx>
#include <ProjLib.hxx>
#include <ElSLib.hxx>
#include <Precision.hxx>
#include <BRepPrimAPI_MakeBox.hxx>
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <BRepPrimAPI_MakeSphere.hxx>
#include <BRepPrimAPI_MakeCone.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS_Solid.hxx>
#include <TopoDS_Edge.hxx>
#ifdef WNT
#include <WNT_Window.hxx>
#include <Graphic3d_WNTGraphicDevice.hxx>
#else
#include <Xw_Window.hxx>
#include <Graphic3d_GraphicDevice.hxx>
#endif // WNT
/*----------------------------------------------------------------------*/
#ifdef WNT
static Handle(Graphic3d_WNTGraphicDevice) defaultdevice;
#else
static Handle(Graphic3d_GraphicDevice) defaultdevice;
#endif // WNT
Handle(V3d_AmbientLight) myCurrent_AmbientLight;
Handle(V3d_SpotLight) myCurrent_SpotLight;
Handle(V3d_PositionalLight) myCurrent_PositionalLight;
Handle(V3d_DirectionalLight) myCurrent_DirectionalLight;
Handle(V3d_Plane) myPlane;
Handle(AIS_Shape) myShape;
gp_Pnt p1, p2, p3;
Handle(AIS_Shape) spotConeShape=new AIS_Shape(TopoDS_Solid());
Handle(AIS_Shape) directionalEdgeShape=new AIS_Shape(TopoDS_Edge());
Standard_Boolean isConeDisplayed = Standard_False;
Standard_Boolean isEdgeDisplayed = Standard_False;
/*----------------------------------------------------------------------*/
gp_Pnt ConvertClickToPoint(Standard_Real x, Standard_Real y, Handle(V3d_View) aView)
{
V3d_Coordinate XEye,YEye,ZEye,XAt,YAt,ZAt;
aView->Eye(XEye,YEye,ZEye);
aView->At(XAt,YAt,ZAt);
gp_Pnt EyePoint(XEye,YEye,ZEye);
gp_Pnt AtPoint(XAt,YAt,ZAt);
gp_Vec EyeVector(EyePoint,AtPoint);
gp_Dir EyeDir(EyeVector);
gp_Pln PlaneOfTheView = gp_Pln(AtPoint,EyeDir);
V3d_Coordinate X,Y,Z;
aView->Convert(Standard_Integer(x),Standard_Integer(y),X,Y,Z);
gp_Pnt ConvertedPoint(X,Y,Z);
gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project(PlaneOfTheView,ConvertedPoint);
gp_Pnt ResultPoint = ElSLib::Value(ConvertedPointOnPlane.X(),
ConvertedPointOnPlane.Y(),
PlaneOfTheView);
return ResultPoint;
}
//===============================================================
// Function name: CreateViewer
//===============================================================
Handle(V3d_Viewer) SampleViewer3DPackage::CreateViewer(const Standard_ExtString aName)
{
#ifndef WNT
if (defaultdevice.IsNull()) defaultdevice = new Graphic3d_GraphicDevice("");
return new V3d_Viewer(defaultdevice, aName);
#else
if (defaultdevice.IsNull()) defaultdevice = new Graphic3d_WNTGraphicDevice();
return new V3d_Viewer(defaultdevice, aName);
#endif //WNT
}
//===============================================================
// Function name: SetWindow
//===============================================================
void SampleViewer3DPackage::SetWindow (const Handle(V3d_View)& aView,
const Standard_Integer hiwin,
const Standard_Integer lowin)
{
#ifdef WNT
Handle(Graphic3d_WNTGraphicDevice) d =
Handle(Graphic3d_WNTGraphicDevice)::DownCast(aView->Viewer()->Device());
Handle(WNT_Window) w = new WNT_Window(d,hiwin,lowin);
#else
Handle(Graphic3d_GraphicDevice) d =
Handle(Graphic3d_GraphicDevice)::DownCast(aView->Viewer()->Device());
Handle(Xw_Window) w = new Xw_Window(d,hiwin,lowin,Xw_WQ_3DQUALITY);
#endif
aView->SetWindow(w);
}
//===============================================================
// Function name: CreateGraphicDriver
//===============================================================
Handle(Graphic3d_GraphicDriver) SampleViewer3DPackage::CreateGraphicDriver()
{
#ifndef WNT
if (defaultdevice.IsNull())
defaultdevice = new Graphic3d_GraphicDevice("");
return Handle(Graphic3d_GraphicDriver)::DownCast(defaultdevice->GraphicDriver());
#else
if (defaultdevice.IsNull())
defaultdevice = new Graphic3d_WNTGraphicDevice();
return Handle(Graphic3d_GraphicDriver)::DownCast(defaultdevice->GraphicDriver());
#endif //WNT
}
//======================================================================
//= =
//= Display figures =
//= =
//======================================================================
//===============================================================
// Function name: DisplayBox
//===============================================================
void SampleViewer3DPackage::DisplayBox(const Handle(AIS_InteractiveContext)& aContext)
{
BRepPrimAPI_MakeBox B(gp_Pnt(0,-400,-100), 200.,150.,100.);
Handle(AIS_Shape) aBox = new AIS_Shape(B.Shape());
aContext->Display(aBox);
}
//===============================================================
// Function name: DisplayCylinder
//===============================================================
void SampleViewer3DPackage::DisplayCylinder(const Handle(AIS_InteractiveContext)& aContext)
{
gp_Ax2 CylAx2(gp_Pnt(0,0,-100), gp_Dir(gp_Vec(gp_Pnt(0,0,-100),gp_Pnt(0,0,100))));
BRepPrimAPI_MakeCylinder C(CylAx2, 80.,200.);
Handle(AIS_Shape) aCyl = new AIS_Shape(C.Shape());
aContext->SetColor(aCyl,Quantity_NOC_WHITE);
aContext->SetMaterial(aCyl,Graphic3d_NOM_SHINY_PLASTIC);
aContext->SetDisplayMode(aCyl,1);
aContext->Display(aCyl);
}
//===============================================================
// Function name: DisplaySphere
//===============================================================
void SampleViewer3DPackage::DisplaySphere(const Handle(AIS_InteractiveContext)& aContext)
{
BRepPrimAPI_MakeSphere S(gp_Pnt(0,300,0), 100.);
Handle(AIS_Shape) aSphere = new AIS_Shape(S.Shape());
aContext->SetMaterial(aSphere,Graphic3d_NOM_SILVER);
aContext->SetDisplayMode(aSphere,1);
aContext->Display(aSphere);
}
//===============================================================
// Function name: EraseAll
//===============================================================
void SampleViewer3DPackage::EraseAll(const Handle(AIS_InteractiveContext)& aContext)
{
aContext->EraseAll(Standard_False);
}
//======================================================================
//= =
//= Spot Light =
//= =
//======================================================================
//===============================================================
// Function name: CreateSpotLight
//===============================================================
void SampleViewer3DPackage::CreateSpotLight(const Handle(AIS_InteractiveContext)& aContext,
TCollection_AsciiString& Message)
{
// Spot light source creation
aContext->OpenLocalContext();
Message = "\
myCurrent_SpotLight = new V3d_SpotLight(myView->Viewer(), Xt, Yt, Zt, Xp, Yp, Zp,Quantity_NOC_RED);\n\
\n\
myView->SetLightOn(myCurrent_SpotLight);\n\
\n\
";
}
//===============================================================
// Function name: SetSpotLight
//===============================================================
void SampleViewer3DPackage::SetSpotLight(const Handle(AIS_InteractiveContext)& aContext,
const Handle(V3d_View)& aView,
const Standard_Integer X,const Standard_Integer Y,
TCollection_AsciiString& Message)
{
p1 = ConvertClickToPoint(X,Y,aView);
myCurrent_SpotLight = new V3d_SpotLight(aView->Viewer(),0.,0.,1., p1.X(),p1.Y(),p1.Z(),
Quantity_NOC_RED);
aView->SetLightOn(myCurrent_SpotLight);
p2 = gp_Pnt(p1.X(),p1.Y(),p1.Z()+1.);
Standard_Real coneHeigth=p1.Distance(p2);
BRepPrimAPI_MakeCone MakeCone(gp_Ax2(p1, gp_Dir(gp_Vec(p1, p2))),
0, (p1.Distance(p2))/tan(1.04), coneHeigth);
spotConeShape->Set(MakeCone.Solid());
if (isConeDisplayed)
aContext->Redisplay(spotConeShape,0,-1);
else
isConeDisplayed = Standard_True;
aContext->Display(spotConeShape,0,-1);
Message = "\
myCurrent_SpotLight->SetDirection(Xv, Yv, Zv);\n\
";
}
//===============================================================
// Function name: DirectingSpotLight
//===============================================================
void SampleViewer3DPackage::DirectingSpotLight(const Handle(AIS_InteractiveContext)& aContext,
const Handle(V3d_View)& aView,
const Standard_Integer X,const Standard_Integer Y)
{
p2 = ConvertClickToPoint(X,Y,aView);
//Update the light dynamically
Standard_Real coneHeigth=p1.Distance(p2);
if( coneHeigth>Precision::Confusion())
{
BRepPrimAPI_MakeCone MakeCone(gp_Ax2(p1, gp_Dir(gp_Vec(p1, p2))),
0, (p1.Distance(p2))/tan(1.04), coneHeigth);
spotConeShape->Set(MakeCone.Solid());
aContext->Redisplay(spotConeShape,0,-1);
myCurrent_SpotLight->SetDirection(p2.X()-p1.X(),p2.Y()-p1.Y(),p2.Z()-p1.Z());
aView->UpdateLights();
}
}
//===============================================================
// Function name: DirectSpotLight
//===============================================================
void SampleViewer3DPackage::DirectSpotLight(const Handle(V3d_View)& aView,
const Standard_Integer X,const Standard_Integer Y,
TCollection_AsciiString& Message)
{
p2 = ConvertClickToPoint(X,Y,aView);
Message = "\
myCurrent_SpotLight->SetAngle(Angle) ;\n\
";
}
//===============================================================
// Function name: ExpandingSpotLight
//===============================================================
void SampleViewer3DPackage::ExpandingSpotLight(const Handle(AIS_InteractiveContext)& aContext,
const Handle(V3d_View)& aView,
const Standard_Integer X,const Standard_Integer Y)
{
p3 = ConvertClickToPoint(X,Y,aView);
//Update the light dynamically
Standard_Real coneHeigth=p1.Distance(p2);
if( (p2.Distance(p3))>Precision::Confusion())
{
BRepPrimAPI_MakeCone MakeCone(gp_Ax2(p1, gp_Dir(gp_Vec(p1, p2))),
0, p2.Distance(p3), coneHeigth);
spotConeShape->Set(MakeCone.Solid());
aContext->Redisplay(spotConeShape,0,-1);
myCurrent_SpotLight->SetAngle(atan(p2.Distance(p3)/p1.Distance(p2))) ;
aView->UpdateLights();
}
}
//===============================================================
// Function name: ExpandSpotLight
//===============================================================
void SampleViewer3DPackage::ExpandSpotLight(const Handle(AIS_InteractiveContext)& aContext)
{
aContext->Erase(spotConeShape);
aContext->CloseLocalContext();
}
//======================================================================
//= =
//= Positional Light =
//= =
//======================================================================
//===============================================================
// Function name: CreatePositionalLight
//===============================================================
void SampleViewer3DPackage::CreatePositionalLight(const Handle(AIS_InteractiveContext)& aContext,
const Handle(V3d_View)& aView,
TCollection_AsciiString& Message)
{
// Positional light source creation
aContext->OpenLocalContext();
myCurrent_PositionalLight=new V3d_PositionalLight(aView->Viewer(),0,0,0,Quantity_NOC_GREEN,1,0);
aView->SetLightOn(myCurrent_PositionalLight);
Message = "\
myCurrent_PositionalLight=new V3d_PositionalLight(myView->Viewer(),Xp, Yp, Zp,Quantity_NOC_GREEN,1,0);\n\
\n\
myView->SetLightOn(myCurrent_PositionalLight) ;\n\
";
}
//===============================================================
// Function name: DirectingPositionalLight
//===============================================================
void SampleViewer3DPackage::DirectingPositionalLight(const Handle(V3d_View)& aView,
const Standard_Integer X,const Standard_Integer Y)
{
p2 = ConvertClickToPoint(X,Y,aView);
//Update the light dynamically
myCurrent_PositionalLight->SetPosition(p2.X(),p2.Y(),p2.Z());
aView->UpdateLights();
}
//===============================================================
// Function name: DirectPositionalLight
//===============================================================
void SampleViewer3DPackage::DirectPositionalLight(const Handle(AIS_InteractiveContext)& aContext,
const Handle(V3d_View)& aView,
const Standard_Integer X,const Standard_Integer Y,
TCollection_AsciiString& Message)
{
p1 = ConvertClickToPoint(X,Y,aView);
myCurrent_PositionalLight->SetPosition(p1.X(),p1.Y(),p1.Z()) ;
aContext->CloseLocalContext();
Message = "\
myCurrent_PositionalLight->SetPosition(Xp, Yp, Zp) ;\n\
";
}
//======================================================================
//= =
//= Directional Light =
//= =
//======================================================================
//===============================================================
// Function name: CreateDirectionalLight
//===============================================================
void SampleViewer3DPackage::CreateDirectionalLight(const Handle(AIS_InteractiveContext)& aContext,
TCollection_AsciiString& Message)
{
// Directional light source creation
aContext->OpenLocalContext();
Message = "\
myCurrent_DirectionalLight = new V3d_DirectionalLight(myView->Viewer(), Xt, Yt, Zt, Xp, Yp, Zp);\n\
\n\
myView->SetLightOn(myCurrent_DirectionalLight);\n\
\n\
";
}
//===============================================================
// Function name: SetDirectionalLight
//===============================================================
void SampleViewer3DPackage::SetDirectionalLight(const Handle(AIS_InteractiveContext)& aContext,
const Handle(V3d_View)& aView,
const Standard_Integer X,const Standard_Integer Y,
TCollection_AsciiString& Message)
{
p1 = ConvertClickToPoint(X,Y,aView);
p2 = gp_Pnt(p1.X(),p1.Y(),p1.Z()+1.);
BRepBuilderAPI_MakeEdge MakeEdge(p1, p2);
directionalEdgeShape->Set(MakeEdge.Edge());
if (isEdgeDisplayed)
aContext->Redisplay(directionalEdgeShape,0,-1);
else
isEdgeDisplayed = Standard_True;
aContext->Display(directionalEdgeShape,0,-1);
// Create a directional light
myCurrent_DirectionalLight = new V3d_DirectionalLight(aView->Viewer(), p1.X(),p1.Y(),p1.Z(),0.,0.,1.);
aView->SetLightOn(myCurrent_DirectionalLight);
Message = "\
myCurrent_DirectionalLight->SetDirection(Xv, Yv, Zv);\n\
";
}
//===============================================================
// Function name: DirectingDirectionalLight
//===============================================================
void SampleViewer3DPackage::DirectingDirectionalLight(const Handle(AIS_InteractiveContext)& aContext,
const Handle(V3d_View)& aView,
const Standard_Integer X,const Standard_Integer Y)
{
p2 = ConvertClickToPoint(X,Y,aView);
//Update the light dynamically
if( p1.Distance(p2)>Precision::Confusion())
{
BRepBuilderAPI_MakeEdge MakeEdge(p1, p2);
directionalEdgeShape->Set(MakeEdge.Edge());
aContext->Redisplay(directionalEdgeShape,0,-1);
myCurrent_DirectionalLight->SetDirection(p2.X()-p1.X(),p2.Y()-p1.Y(),p2.Z()-p1.Z());
aView->UpdateLights();
}
}
//===============================================================
// Function name: DirectDirectionalLight
//===============================================================
void SampleViewer3DPackage::DirectDirectionalLight(const Handle(AIS_InteractiveContext)& aContext)
{
aContext->Erase(directionalEdgeShape);
aContext->CloseLocalContext();
}
//======================================================================
//= =
//= Ambient Light =
//= =
//======================================================================
//===============================================================
// Function name: CreateAmbientLight
//===============================================================
void SampleViewer3DPackage::CreateAmbientLight(const Handle(AIS_InteractiveContext)& aContext,
const Handle(V3d_View)& aView,
TCollection_AsciiString& Message)
{
// Ambient light source creation
aContext->OpenLocalContext();
myCurrent_AmbientLight=new V3d_AmbientLight(aView->Viewer(), Quantity_NOC_GRAY);
aView->SetLightOn(myCurrent_AmbientLight) ;
aContext->CloseLocalContext();
aView->UpdateLights();
Message = "\
myCurrent_AmbientLight=new V3d_AmbientLight(myView->Viewer(), Quantity_NOC_GRAY);\n\
\n\
myView->SetLightOn(myCurrent_AmbientLight) ;\n\
";
}
//===============================================================
// Function name: ClearLights
//===============================================================
void SampleViewer3DPackage::ClearLights(const Handle(V3d_View)& aView,
TCollection_AsciiString& Message)
{
// Setting Off all non global active lights
for(aView->InitActiveLights(); aView->MoreActiveLights(); aView->NextActiveLights())
{
if (!aView->Viewer()->IsGlobalLight(aView->ActiveLight()))
aView->SetLightOff(aView->ActiveLight());
}
aView->Update();
Message = "\
for(myView->InitActiveLights(); myView->MoreActiveLights(); myView->NextActiveLights())\n\
{\n\
if (!aView->Viewer()->IsGlobalLight(aView->ActiveLight()))\n\
myView->SetLightOff(myView->ActiveLight()); //Setting Off all non global active lights\n\
}\n\
";
}
//======================================================================
//= =
//= ZClipping =
//= =
//======================================================================
//===============================================================
// Function name: ChangeZClippingDepth
//===============================================================
void SampleViewer3DPackage::ChangeZClippingDepth(const Handle(V3d_View)& aView,
const Quantity_Length Depth,
TCollection_AsciiString& Message)
{
// Setting the ZClipping depth at Depth value
aView->SetZClippingDepth(Depth);
aView->Update();
Message = "\
myView->SetZClippingDepth(Depth);\n\
\n\
myView->Update();\n\
";
}
//===============================================================
// Function name: ChangeZClippingWidth
//===============================================================
void SampleViewer3DPackage::ChangeZClippingWidth(const Handle(V3d_View)& aView,
const Quantity_Length Width,
TCollection_AsciiString& Message)
{
// Setting the ZClipping width at Width value
aView->SetZClippingWidth(Width);
aView->Update();
Message = "\
myView->SetZClippingWidth(Width);\n\
\n\
myView->Update();\n\
";
}
//===============================================================
// Function name: ChangeZClippingType
//===============================================================
void SampleViewer3DPackage::ChangeZClippingType(const Handle(V3d_View)& aView,
const V3d_TypeOfZclipping Type,
TCollection_AsciiString& Message)
{
// Setting the ZClipping type at Type value
aView->SetZClippingType(Type);
aView->Update();
Message = "\
aView->SetZClippingType(Type);\n\
\n\
aView->Update();\n\
";
}
//======================================================================
//= =
//= ZCueing =
//= =
//======================================================================
//===============================================================
// Function name: ChangeZCueingDepth
//===============================================================
void SampleViewer3DPackage::ChangeZCueingDepth(const Handle(V3d_View)& aView,
const Quantity_Length Depth,
TCollection_AsciiString& Message)
{
// Setting the ZCueing depth at Depth value
aView->SetZCueingDepth(Depth);
aView->Update();
Message = "\
myView->SetZCueingDepth(Depth);\n\
\n\
myView->Update();\n\
";
}
//===============================================================
// Function name: ChangeZCueingWidth
//===============================================================
void SampleViewer3DPackage::ChangeZCueingWidth(const Handle(V3d_View)& aView,
const Quantity_Length Width,
TCollection_AsciiString& Message)
{
// Setting the ZCueing width at Width value
aView->SetZCueingWidth(Width);
aView->Update();
Message = "\
myView->SetZCueingWidth(Width);\n\
\n\
myView->Update();\n\
";
}
//===============================================================
// Function name: ChangeZCueingOnOff
//===============================================================
void SampleViewer3DPackage::ChangeZCueingOnOff(const Handle(V3d_View)& aView,
const Standard_Boolean IsOn,
TCollection_AsciiString& Message)
{
Quantity_Length Depth, Width;
if(IsOn)
{
if(!aView->ZCueing(Depth, Width))
// Setting the ZCueing on if it's not yet
aView->SetZCueingOn();
}
else
{
if(aView->ZCueing(Depth, Width))
// Setting the ZCueing off if it's not yet
aView->SetZCueingOff();
}
aView->Update();
Message = "\
if(!myView->ZCueing(Depth, Width));\n\
myView->SetZCueingOn();\n\
else\n\
myView->SetZCueingOff();\n\
\n\
myView->Update();\n\
";
}
//======================================================================
//= =
//= Other modes =
//= =
//======================================================================
//===============================================================
// Function name: ChangeShadingModel
//===============================================================
void SampleViewer3DPackage::ChangeShadingModel(const Handle(V3d_View)& aView,
const V3d_TypeOfShadingModel Model)
{
aView->SetShadingModel(Model);
aView->Update();
}
//===============================================================
// Function name: ChangeAntialiasing
//===============================================================
void SampleViewer3DPackage::ChangeAntialiasing(const Handle(V3d_View)& aView,
TCollection_AsciiString& Message)
{
if(!aView->Antialiasing())
aView->SetAntialiasingOn();
else
aView->SetAntialiasingOff();
aView->Update();
Message = "\
if(!myView->Antialiasing())\n\
myView->SetAntialiasingOn();\n\
else\n\
myView->SetAntialiasingOff();\n\
";
}
//======================================================================
//= =
//= Model Clipping =
//= =
//======================================================================
//===============================================================
// Function name: CreateClippingPlane
//===============================================================
void SampleViewer3DPackage::CreateClippingPlane(const Handle(V3d_Viewer)& aViewer)
{
if( myPlane.IsNull() )
{
//creates a plane defined : center of the box ( 50,50,50) and 1 direction
gp_Pln tmpPln(gp_Pnt(0,0,0),gp_Dir(1,0,0));
//getting the coefficients of the gp_Pln ( ax+by+cz+d = 0 )
Standard_Real A,B,C,D;
tmpPln.Coefficients(A,B,C,D);
//with these coefficients, creating a V3d_Plane
myPlane = new V3d_Plane(aViewer,A,B,C,D);
//creates the Face
//NOTE : the face must be behind the clipping plane !!
tmpPln = gp_Pln(gp_Pnt(0.1,0,0),gp_Dir(1,0,0));
BRepBuilderAPI_MakeFace MakeFace(tmpPln, 200, -200, 410, -410);
TopoDS_Face S = MakeFace.Face();
//display the face
myShape = new AIS_Shape(S);
}
}
//===============================================================
// Function name: DisplayClippingPlane
//===============================================================
void SampleViewer3DPackage::DisplayClippingPlane(const Handle(AIS_InteractiveContext)& aContext,
const Handle(V3d_View)& aView,
Standard_Real& Z,Standard_Boolean& IsOn)
{
Standard_Real A,B,C,D;
myPlane->Plane(A,B,C,D);
Z = D;
Handle(V3d_Plane) thePlane;
for (aView->InitActivePlanes();
aView->MoreActivePlanes();
aView->NextActivePlanes()) {
thePlane = aView->ActivePlane() ;
if (thePlane == myPlane) IsOn = Standard_True;
}
if (IsOn)
if (!myShape.IsNull())
aContext->Display(myShape);
}
//===============================================================
// Function name: ChangeModelClippingZ
//===============================================================
void SampleViewer3DPackage::ChangeModelClippingZ(const Handle(AIS_InteractiveContext)& aContext,
const Handle(V3d_View)& aView,const Standard_Real Z,
const Standard_Boolean IsOn,
TCollection_AsciiString& Message)
{
// Setting the ModelClippingZ at Z value
gp_Pln clipPln(gp_Pnt(-Z,0,0),gp_Dir(1,0,0));
Standard_Real A,B,C,D;
clipPln.Coefficients(A,B,C,D);
myPlane->SetPlane(A,B,C,D);
if(IsOn)
aView->SetPlaneOn(myPlane);
gp_Trsf myTrsf;
myTrsf.SetTranslation(gp_Pnt(Z,0,0), gp_Pnt(0,0,0));
aContext->SetLocation(myShape,TopLoc_Location(myTrsf)) ;
aContext->Redisplay(myShape);
aView->Update();
Message = "\
gp_Pln clipPln(gp_Pnt(-Z,0,0),gp_Dir(1,0,0));\n\
Standard_Real A,B,C,D;\n\
clipPln.Coefficients(A,B,C,D);\n\
myPlane->SetPlane(A,B,C,D);\n\
myView->SetPlaneOn(myPlane); \n\
";
}
//===============================================================
// Function name: ChangeModelClippingOnOff
//===============================================================
void SampleViewer3DPackage::ChangeModelClippingOnOff(const Handle(AIS_InteractiveContext)& aContext,
const Handle(V3d_View)& aView,
const Standard_Boolean IsOn,
TCollection_AsciiString& Message)
{
if (IsOn)
{
//activate the plane
aView->SetPlaneOn(myPlane);
aContext->Display(myShape);
}
else
//deactivate the plane
{
aView->SetPlaneOff(myPlane);
aContext->Erase(myShape);
}
aView->Update();
Message = "\
if(IsOn) \n\
myView->SetPlaneOn(myPlane); \n\
else \n\
myView->SetPlaneOff(myPlane); \n\
";
}
//===============================================================
// Function name: ClearClippingPlane
//===============================================================
void SampleViewer3DPackage::ClearClippingPlane(const Handle(AIS_InteractiveContext)& aContext,
const Handle(V3d_View)& aView,
const Standard_Boolean IsOn)
{
if (IsOn)
//deactivate the plane
aView->SetPlaneOff(myPlane);
if(!myShape.IsNull())
aContext->Erase(myShape);
if (IsOn)
aView->Update();
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,97 @@
#include <User_Cylinder.ixx>
#include <AIS_InteractiveObject.hxx>
#include <AIS_Drawer.hxx>
#include <BRepPrimAPI_MakeCylinder.hxx>
#include <Prs3d_ShadingAspect.hxx>
#include <TopExp_Explorer.hxx>
#include <BRep_Tool.hxx>
#include <TopoDS.hxx>
#include <Geom_Surface.hxx>
#include <Geom_Plane.hxx>
#include <StdPrs_WFDeflectionShape.hxx>
#include <StdPrs_ShadedShape.hxx>
#include <StdPrs_HLRPolyShape.hxx>
#include <StdSelect_BRepSelectionTool.hxx>
User_Cylinder::User_Cylinder(const Standard_Real R,const Standard_Real H)
{
BRepPrimAPI_MakeCylinder S(R,H);
myShape = S.Shape();
SetHilightMode(0);
SetSelectionMode(0);
myDrawer->SetShadingAspect(new Prs3d_ShadingAspect());
myPlanarFaceColor = Quantity_NOC_FIREBRICK3;
myCylindricalFaceColor = Quantity_NOC_AZURE;
}
Standard_Integer User_Cylinder::NbPossibleSelection()
{
return 2;
}
void User_Cylinder::Compute(const Handle(PrsMgr_PresentationManager3d)& aPresentationManager,
const Handle(Prs3d_Presentation)& aPresentation,
const Standard_Integer aMode)
{
switch (aMode)
{
case 0:
StdPrs_WFDeflectionShape::Add(aPresentation,myShape, myDrawer);
break;
case 1:
myDrawer->ShadingAspect()->SetMaterial(Graphic3d_NOM_PLASTIC);
myDrawer->SetShadingAspectGlobal(Standard_False);
TopExp_Explorer Ex;
Handle(Geom_Surface) Surface;
for (Ex.Init(myShape,TopAbs_FACE); Ex.More(); Ex.Next())
{
Surface = BRep_Tool::Surface(TopoDS::Face(Ex.Current()));
if (Surface->IsKind(STANDARD_TYPE(Geom_Plane)))
myDrawer->ShadingAspect()->SetColor(myPlanarFaceColor);
else
myDrawer->ShadingAspect()->SetColor(myCylindricalFaceColor);
StdPrs_ShadedShape::Add(aPresentation,Ex.Current(), myDrawer);
}
break;
}
}
void User_Cylinder::Compute(const Handle(Prs3d_Projector)& aProjector,
const Handle(Prs3d_Presentation)& aPresentation)
{
myDrawer->EnableDrawHiddenLine();
StdPrs_HLRPolyShape::Add(aPresentation,myShape, myDrawer, aProjector);
}
void User_Cylinder::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection,
const Standard_Integer aMode)
{
switch(aMode)
{
case 0:
StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_SHAPE,0,0);
break;
case 4:
StdSelect_BRepSelectionTool::Load(aSelection,this,myShape,TopAbs_FACE,0,0);
break;
}
}
void User_Cylinder::SetCylindricalFaceColor(const Quantity_NameOfColor aColor)
{
myCylindricalFaceColor = aColor;
}
void User_Cylinder::SetPlanarFaceColor(const Quantity_NameOfColor aColor)
{
myPlanarFaceColor = aColor;
}
Standard_Boolean User_Cylinder::AcceptShapeDecomposition() const
{
return Standard_True;
}