//! Convert 1 OCC edge into 1 BaseGeom (static factory method)
BaseGeom* BaseGeom::baseFactory(TopoDS_Edge edge)
{
    BaseGeom* result = NULL;
    BRepAdaptor_Curve adapt(edge);
    switch(adapt.GetType()) {
      case GeomAbs_Circle: {
        double f = adapt.FirstParameter();
        double l = adapt.LastParameter();
        gp_Pnt s = adapt.Value(f);
        gp_Pnt e = adapt.Value(l);

        if (fabs(l-f) > 1.0 && s.SquareDistance(e) < 0.001) {
              Circle *circle = new Circle(edge);
              result = circle;
        } else {
              AOC *aoc = new AOC(edge);
              result = aoc;
        }
      } break;
      case GeomAbs_Ellipse: {
        double f = adapt.FirstParameter();
        double l = adapt.LastParameter();
        gp_Pnt s = adapt.Value(f);
        gp_Pnt e = adapt.Value(l);
        if (fabs(l-f) > 1.0 && s.SquareDistance(e) < 0.001) {
              Ellipse *ellipse = new Ellipse(edge);
              result = ellipse;
        } else {
              AOE *aoe = new AOE(edge);
              result = aoe;
        }
      } break;
      case GeomAbs_BezierCurve: {
          Handle_Geom_BezierCurve bez = adapt.Bezier();
          //if (bez->Degree() < 4) {
          result = new BezierSegment(edge);
          //}
          //    OCC is quite happy with Degree > 3 but QtGui handles only 2,3
      } break;
      case GeomAbs_BSplineCurve: {
        BSpline *bspline = 0;
        Generic* gen = NULL;
        try {
            bspline = new BSpline(edge);
            if (bspline->isLine()) {
                gen = new Generic(edge);
                result = gen;
                delete bspline;
                bspline = nullptr;
            } else {
                result = bspline;
            }
            break;
        }
        catch (Standard_Failure) {
            if (bspline != nullptr) {
                delete bspline;
                bspline = nullptr;
            }
            if (gen != nullptr) {
                delete gen;
                gen = nullptr;
            }
        }
      }
      default: {
        Generic *primitive = new Generic(edge);
        result = primitive;
      }  break;
    }
    return result;
}
예제 #2
0
//! Convert 1 OCC edge into 1 BaseGeom (static factory method)
BaseGeom* BaseGeom::baseFactory(TopoDS_Edge edge)
{
    BaseGeom* result = NULL;
    BRepAdaptor_Curve adapt(edge);

    switch(adapt.GetType()) {
      case GeomAbs_Circle: {
        double f = adapt.FirstParameter();
        double l = adapt.LastParameter();
        gp_Pnt s = adapt.Value(f);
        gp_Pnt e = adapt.Value(l);

        if (fabs(l-f) > 1.0 && s.SquareDistance(e) < 0.001) {
              Circle *circle = new Circle(edge);
              //circle->extractType = extractionType;
              result = circle;
        } else {
              AOC *aoc = new AOC(edge);
              //aoc->extractType = extractionType;
              result = aoc;
        }
      } break;
      case GeomAbs_Ellipse: {
        double f = adapt.FirstParameter();
        double l = adapt.LastParameter();
        gp_Pnt s = adapt.Value(f);
        gp_Pnt e = adapt.Value(l);
        if (fabs(l-f) > 1.0 && s.SquareDistance(e) < 0.001) {
              Ellipse *ellipse = new Ellipse(edge);
              //ellipse->extractType = extractionType;
              result = ellipse;
        } else {
              AOE *aoe = new AOE(edge);
              //aoe->extractType = extractionType;
              result = aoe;
        }
      } break;
      case GeomAbs_BSplineCurve: {
        BSpline *bspline = 0;
        Generic* gen = NULL;
        try {
            bspline = new BSpline(edge);
            //bspline->extractType = extractionType;
            if (bspline->isLine()) {
                gen = new Generic(edge);
                //gen->extractType = extractionType;
                result = gen;
                delete bspline;
            } else {
                result = bspline;
            }
            break;
        }
        catch (Standard_Failure) {
            delete bspline;
            delete gen;
            bspline = 0;
            // Move onto generating a primitive
        }
      }
      default: {
        Generic *primitive = new Generic(edge);
        //primitive->extractType = extractionType;
        result = primitive;
      }  break;
    }
    return result;
}