+void CurveCreator_Utils::constructShape( const CurveCreator_ICurve* theCurve,
+ TopoDS_Shape& theShape )
+{
+ BRep_Builder aBuilder;
+ TopoDS_Compound aComp;
+ aBuilder.MakeCompound( aComp );
+ for( int iSection = 0 ; iSection < theCurve->getNbSections() ; iSection++ )
+ {
+ int theISection = iSection;
+
+ CurveCreator::SectionType aSectType = theCurve->getSectionType( theISection );
+ int aPointSize = theCurve->getNbPoints( theISection );
+ bool aSectIsClosed = theCurve->isClosed( theISection );
+ bool isPolyline = aSectType == CurveCreator::Polyline;
+ int iPoint = 0;
+ gp_Pnt aPrevPoint, aPoint;
+ if ( aPointSize == 1 ) {
+ CurveCreator_UtilsICurve::getPoint( theCurve, theISection, iPoint, aPoint );
+ TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex();
+ aBuilder.Add( aComp, aVertex );
+ }
+ else if ( aPointSize > 1 ) {
+ Handle(TColgp_HArray1OfPnt) aHCurvePoints = new TColgp_HArray1OfPnt (1, aPointSize);
+ int aHIndex = 1;
+
+ TopoDS_Edge aPointEdge;
+ TopoDS_Vertex aVertex;
+ CurveCreator_UtilsICurve::getPoint( theCurve, theISection, iPoint, aPoint );
+ aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex();
+ aBuilder.Add( aComp, aVertex );
+ aHCurvePoints->SetValue(aHIndex++, aPoint);
+ aPrevPoint = aPoint;
+ iPoint++;
+ for( ; iPoint < aPointSize; iPoint++ ) {
+ CurveCreator_UtilsICurve::getPoint( theCurve, theISection, iPoint, aPoint );
+ aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex();
+ aBuilder.Add( aComp, aVertex );
+ aHCurvePoints->SetValue(aHIndex++, aPoint);
+ if ( isPolyline ) {
+ aPointEdge = BRepBuilderAPI_MakeEdge( aPrevPoint, aPoint ).Edge();
+ aBuilder.Add( aComp, aPointEdge );
+ }
+ aPrevPoint = aPoint;
+ }
+ if( aSectIsClosed && ( aPointSize > 2 ) ) {
+ CurveCreator_UtilsICurve::getPoint( theCurve, theISection, 0, aPoint );
+ aVertex = BRepBuilderAPI_MakeVertex( aPoint ).Vertex();
+ aBuilder.Add( aComp, aVertex );
+ if ( isPolyline ) {
+ aPointEdge = BRepBuilderAPI_MakeEdge( aPrevPoint, aPoint ).Edge();
+ aBuilder.Add( aComp, aPointEdge );
+ }
+ }
+ if( !isPolyline ) {
+ // compute BSpline
+ Handle(Geom_BSplineCurve) aBSplineCurve;
+ GeomAPI_Interpolate aGBC(aHCurvePoints, aSectIsClosed, gp::Resolution());
+ aGBC.Perform();
+ if ( aGBC.IsDone() )
+ aBSplineCurve = aGBC.Curve();
+ TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge( aBSplineCurve ).Edge();
+ TopoDS_Wire aWire = BRepBuilderAPI_MakeWire( anEdge ).Wire();
+ aBuilder.Add( aComp, aWire );
+ }
+ }
+ }
+ theShape = aComp;
+}
+
+class ComparePnt
+{
+public:
+ ComparePnt( const gp_Pnt& thePoint ) : myPoint( thePoint) {};
+ ~ComparePnt() {}
+
+ bool operator < ( const ComparePnt& theOtherPoint ) const
+ {
+ bool isLess = myPoint.X() < theOtherPoint.myPoint.X();
+ if ( !isLess && myPoint.X() == theOtherPoint.myPoint.X() ) {
+ isLess = myPoint.Y() < theOtherPoint.myPoint.Y();
+ if ( !isLess && myPoint.Y() == theOtherPoint.myPoint.Y() )
+ isLess = myPoint.Z() < theOtherPoint.myPoint.Z();
+ }
+ return isLess;
+ }
+private:
+ gp_Pnt myPoint;
+};
+
+void CurveCreator_Utils::getSelectedPoints( Handle(AIS_InteractiveContext) theContext,
+ const CurveCreator_ICurve* theCurve,
+ CurveCreator_ICurve::SectionToPointList& thePoints )
+{
+ thePoints.clear();
+
+ std::list<float> aSelectedPoints;
+ gp_Pnt aPnt;
+ std::map<ComparePnt, int> aPntMap;
+
+ CurveCreator_ICurve::SectionToPointList aPoints;
+ for ( theContext->InitSelected(); theContext->MoreSelected(); theContext->NextSelected() ) {
+ TopoDS_Vertex aVertex;
+ TopoDS_Shape aShape = theContext->SelectedShape();
+ if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
+ aVertex = TopoDS::Vertex( theContext->SelectedShape() );
+
+ if ( aVertex.IsNull() )
+ continue;
+ aPnt = BRep_Tool::Pnt( aVertex );
+ if ( aPntMap.find( aPnt ) != aPntMap.end() )
+ continue;
+ aPntMap[aPnt] = 0;
+
+ CurveCreator_UtilsICurve::findSectionsToPoints( theCurve, aPnt.X(), aPnt.Y(), aPoints );
+ CurveCreator_ICurve::SectionToPointList::const_iterator anIt = aPoints.begin(),
+ aLast = aPoints.end();
+ for ( ; anIt != aLast; anIt++ )
+ thePoints.push_back( *anIt );
+ }
+}
+
+void CurveCreator_Utils::setSelectedPoints( Handle(AIS_InteractiveContext) theContext,
+ const CurveCreator_ICurve* theCurve,
+ const CurveCreator_ICurve::SectionToPointList& thePoints )
+{
+ if ( !theCurve )
+ return;
+
+ Handle(AIS_InteractiveObject) anAIS = theCurve->getAISObject();
+ if ( anAIS.IsNull() )
+ return;
+ Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast( anAIS );
+ if ( anAISShape.IsNull() )
+ return;
+
+ //ASL: we convert list of point indices to list of points coordinates
+ int aSize = thePoints.size();
+ std::vector<gp_Pnt> aPntsToSelect( aSize );
+
+ CurveCreator_ICurve::SectionToPointList::const_iterator
+ aPIt = thePoints.begin(), aPLast = thePoints.end();
+ CurveCreator_ICurve::SectionToPoint aSToPoint;
+ for( int i=0; aPIt != aPLast; aPIt++, i++ )
+ {
+ gp_Pnt aPntToSelect;
+ CurveCreator_UtilsICurve::getPoint( theCurve, aPIt->first, aPIt->second, aPntToSelect );
+ aPntsToSelect[i] = aPntToSelect;
+ }
+
+ theContext->ClearSelected( Standard_False );
+ //ASL: we switch off automatic highlight to improve performance of selection
+ theContext->SetAutomaticHilight( Standard_False );
+
+ Handle_SelectMgr_Selection aSelection = anAISShape->Selection( AIS_Shape::SelectionMode( TopAbs_VERTEX ) );
+ for( aSelection->Init(); aSelection->More(); aSelection->Next() )
+ {
+ Handle_SelectBasics_SensitiveEntity aSenEntity = aSelection->Sensitive();
+ Handle_Select3D_SensitivePoint aSenPnt = Handle_Select3D_SensitivePoint::DownCast( aSenEntity );
+
+ gp_Pnt anOwnerPnt = aSenPnt->Point();
+ Handle_SelectMgr_EntityOwner anOwner = Handle_SelectMgr_EntityOwner::DownCast( aSenPnt->OwnerId() );
+
+
+ CurveCreator_ICurve::SectionToPointList::const_iterator anIt = thePoints.begin(),
+ aLast = thePoints.end();
+ bool isFound = false;
+ for( int i=0; i<aSize; i++ )
+ {
+ bool isIntersect = fabs( aPntsToSelect[i].X() - anOwnerPnt.X() ) < LOCAL_SELECTION_TOLERANCE &&
+ fabs( aPntsToSelect[i].Y() - anOwnerPnt.Y() ) < LOCAL_SELECTION_TOLERANCE;
+ if( isIntersect )
+ {
+ theContext->AddOrRemoveSelected( anOwner, Standard_False );
+ break;
+ }
+ }
+ }
+
+ //ASL: we switch on again automatic highlight (otherwise selection will not be shown)
+ // and call HilightPicked to draw selected owners
+ theContext->SetAutomaticHilight( Standard_True );
+ theContext->LocalContext()->HilightPicked( Standard_True );
+}
+