// Copyright (c) 1995-1999 Matra Datavision // Copyright (c) 1999-2012 OPEN CASCADE SAS // // The content of this file is subject to the Open CASCADE Technology Public // License Version 6.5 (the "License"). You may not use the content of this file // except in compliance with the License. Please obtain a copy of the License // at http://www.opencascade.org and read it completely before using this file. // // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. // // The Original Code and all software distributed under the License is // distributed on an "AS IS" basis, without warranty of any kind, and the // Initial Developer hereby disclaims all such warranties, including without // limitation, any warranties of merchantability, fitness for a particular // purpose or non-infringement. Please see the License for the specific terms // and conditions governing the rights and limitations under the License. #include #include #include #include #include #include #include #include #include static void DrawLine (const anyLine& aLine, const Handle(Graphic3d_Group)& aGroup) { Quantity_Length x,y,z; Standard_Integer i = LineTool::Lower(aLine); const Standard_Integer Upper = LineTool::Upper(aLine); Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(Upper-i+1); for (; i <= Upper; i++) { LineTool::Coord(aLine,i,x,y,z); aPrims->AddVertex((Standard_ShortReal)x,(Standard_ShortReal)y,(Standard_ShortReal)z); } aGroup->AddPrimitiveArray(aPrims); } void Prs3d_Line::Add (const Handle (Prs3d_Presentation)& aPresentation, const anyLine& aLine, const Handle (Prs3d_Drawer)& aDrawer) { Handle(Graphic3d_Group) TheGroup = Prs3d_Root::CurrentGroup(aPresentation); TheGroup->SetPrimitivesAspect(aDrawer->LineAspect()->Aspect()); DrawLine(aLine,TheGroup); if (aDrawer->LineArrowDraw()) { Standard_Integer Lower = LineTool::Lower(aLine); Standard_Integer Upper = LineTool::Upper(aLine); if ( Upper > Lower ){ Quantity_Length x1,y1,z1,x2,y2,z2; LineTool::Coord(aLine,Upper-1,x1,y1,z1); LineTool::Coord(aLine,Upper,x2,y2,z2); Prs3d_Arrow::Draw(aPresentation, gp_Pnt(x2,y2,z2), gp_Dir(x2-x1,y2-y1,z2-z1), aDrawer->ArrowAspect()->Angle(), aDrawer->ArrowAspect()->Length()); } } } void Prs3d_Line::Add (const Handle (Prs3d_Presentation)& aPresentation, const anyLine& aLine) { DrawLine (aLine,Prs3d_Root::CurrentGroup(aPresentation)); } Standard_Integer Prs3d_Line::Pick (const Quantity_Length X, const Quantity_Length Y, const Quantity_Length Z, const Quantity_Length aDistance, const anyLine& aLine, const Handle (Prs3d_Drawer)& aDrawer, const Prs3d_TypeOfLinePicking TypeOfPicking) { Standard_Integer i = LineTool::Lower(aLine); const Standard_Integer Upper = LineTool::Upper(aLine); Standard_Integer num = 0; Quantity_Length X1,Y1,Z1,X2,Y2,Z2,dist; Standard_Real DistMin = RealLast(); for (; i <= Upper; i++) { LineTool::Coord(aLine,i,X2,Y2,Z2); switch (TypeOfPicking) { case Prs3d_TOLP_Point: { dist = Abs(X-X2)+Abs(Y-Y2)+ Abs(Z-Z2); if(dist < aDistance) { if (dist < DistMin) { DistMin = dist; num = i; } } break; } case Prs3d_TOLP_Segment: { if (i > 1) { if (Prs3d::MatchSegment(X,Y,Z,aDistance,gp_Pnt(X1,Y1,Z1),gp_Pnt(X2,Y2,Z2),dist)) { if(dist < aDistance) { if (dist < DistMin) { DistMin = dist; num = i; } } } } X1=X2;Y1=Y2;Z1=Z2; break; } } } return num; }