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
+113
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 )
{
}
@@ -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;
}
+43
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();
}
+99
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;
}
+278
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 )
{
}