• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ TopLoc_Location类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中TopLoc_Location的典型用法代码示例。如果您正苦于以下问题:C++ TopLoc_Location类的具体用法?C++ TopLoc_Location怎么用?C++ TopLoc_Location使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了TopLoc_Location类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: OCCTesselation

OCCTesselation *OCCEdge::tesselate(double angular, double curvature)
{
    OCCTesselation *ret = new OCCTesselation();
    try {
        Standard_Real start, end;
        OCCStruct3f vert;
        
        TopLoc_Location loc = this->getEdge().Location();
        gp_Trsf location = loc.Transformation();
        
        const Handle(Geom_Curve)& curve = BRep_Tool::Curve(this->getEdge(), start, end);
        const GeomAdaptor_Curve& aCurve(curve);
		
        GCPnts_TangentialDeflection TD(aCurve, start, end, angular, curvature);
        
        for (Standard_Integer i = 1; i <= TD.NbPoints(); i++)
        {
            gp_Pnt pnt = TD.Value(i).Transformed(location);
            vert.x = (float)pnt.X();
            vert.y = (float)pnt.Y();
            vert.z = (float)pnt.Z();
            ret->vertices.push_back(vert);
        }
        
        ret->ranges.push_back(0);
        ret->ranges.push_back(ret->vertices.size());
        
    } catch(Standard_Failure &err) {
        return NULL;
    }
    return ret;
}
开发者ID:erossignon,项目名称:occmodel,代码行数:32,代码来源:OCCEdge.cpp


示例2: ubTreeFiller

void PointOnFacesProjector::prepare(const TopoDS_Shape& faces)
{
  d->clear();
  // Build the UB tree for binary search of points
  internal::UBTreeOfNodeIndicesFiller_t ubTreeFiller(d->m_ubTree, Standard_False);
  for (TopExp_Explorer exp(faces, TopAbs_FACE); exp.More(); exp.Next()) {
    const TopoDS_Face face = TopoDS::Face(exp.Current());
    if (!face.IsNull()) {
      TopLoc_Location loc;
      const Handle_Poly_Triangulation& triangulation = BRep_Tool::Triangulation(face, loc);
      if (!triangulation.IsNull()) {
        d->insertMapping(triangulation, face);
        const gp_Trsf& trsf = loc.Transformation();
        const TColgp_Array1OfPnt& nodes = triangulation->Nodes();
        for (int i = nodes.Lower(); i <= nodes.Upper(); ++i) {
          const gp_Pnt iNode(nodes(i).Transformed(trsf));
          Bnd_Box ibb;
          ibb.Set(iNode);
          ubTreeFiller.Add(std::make_pair(i, triangulation), ibb);
        }
      }
    }
  }
  ubTreeFiller.Fill();
}
开发者ID:Alexandr-Galko,项目名称:fougtools,代码行数:25,代码来源:point_on_faces_projector.cpp


示例3: ax2

App::DocumentObjectExecReturn *Mirroring::execute(void)
{
    App::DocumentObject* link = Source.getValue();
    if (!link)
        return new App::DocumentObjectExecReturn("No object linked");
    if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
        return new App::DocumentObjectExecReturn("Linked object is not a Part object");
    Part::Feature *source = static_cast<Part::Feature*>(link);
    Base::Vector3f base = Base.getValue();
    Base::Vector3f norm = Normal.getValue();

    try {
        const TopoDS_Shape& shape = source->Shape.getValue();
        gp_Ax2 ax2(gp_Pnt(base.x,base.y,base.z), gp_Dir(norm.x,norm.y,norm.z));
        gp_Trsf mat;
        mat.SetMirror(ax2);
        TopLoc_Location loc = shape.Location();
        gp_Trsf placement = loc.Transformation();
        mat = placement * mat;
        BRepBuilderAPI_Transform mkTrf(shape, mat);
        this->Shape.setValue(mkTrf.Shape());
        return App::DocumentObject::StdReturn;
    }
    catch (Standard_Failure) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        return new App::DocumentObjectExecReturn(e->GetMessageString());
    }
}
开发者ID:Daedalus12,项目名称:FreeCAD_sf_master,代码行数:28,代码来源:FeatureMirroring.cpp


示例4: ScanCascadeShapes

void ChCascadeDoc::ScanCascadeShapes(callback_CascadeDoc& mcallback) {
    TopLoc_Location rootloc;
    rootloc.Identity();

    Handle(XCAFDoc_ShapeTool) shapeTool = XCAFDoc_DocumentTool::ShapeTool((*doc)->Main());
    TDF_LabelSequence root_labels;
    shapeTool->GetFreeShapes(root_labels);
    for (Standard_Integer i = 1; i <= root_labels.Length(); i++) {
        TDF_Label label = root_labels.Value(i);
        int level = 0;
        recurse_CascadeDoc(label, shapeTool, rootloc, level, mcallback);
    }
}
开发者ID:armanpazouki,项目名称:chrono,代码行数:13,代码来源:ChCascadeDoc.cpp


示例5: FromChronoToCascade

void ChCascadeDoc::FromChronoToCascade(const ChFrame<>& from_coord, TopLoc_Location& to_coord) {
    const ChVector<>& mpos = from_coord.GetPos();
    gp_Vec mtr(mpos.x(), mpos.y(), mpos.z());

    const ChMatrix33<>& from_mat = from_coord.GetA();

    ((gp_Trsf)(to_coord.Transformation()))
        .SetValues(from_mat(0, 0), from_mat(0, 1), from_mat(0, 2), mpos.x(), from_mat(1, 0), from_mat(1, 1),
                   from_mat(1, 2), mpos.y(), from_mat(2, 0), from_mat(2, 1), from_mat(2, 2), mpos.z()); //0, 0);
}
开发者ID:armanpazouki,项目名称:chrono,代码行数:10,代码来源:ChCascadeDoc.cpp


示例6: OCC2VTK

void  
GEOM_ShadingFace:: 
OCC2VTK(const TopoDS_Face& theFace,  
        vtkPolyData* thePolyData, 
        vtkPoints* thePts) 
{
  TopLoc_Location aLoc;
  Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(theFace,aLoc);
  if(aPoly.IsNull()) 
    return;
  else{
    gp_Trsf myTransf;
    Standard_Boolean identity = true;
    if(!aLoc.IsIdentity()){
      identity = false;
      myTransf = aLoc.Transformation();
    }           
      
    Standard_Integer i; 
    int aNbOfNodes = thePts->GetNumberOfPoints();
    const TColgp_Array1OfPnt& Nodes = aPoly->Nodes();
    Standard_Integer nbNodesInFace = aPoly->NbNodes(); 
    for(i = 1; i <= nbNodesInFace; i++) {
      gp_Pnt P = Nodes(i);
      if(!identity) 
        P.Transform(myTransf);
      thePts->InsertNextPoint(P.X(),P.Y(),P.Z());
    }

    const Poly_Array1OfTriangle& Triangles = aPoly->Triangles();
    Standard_Integer nbTriInFace = aPoly->NbTriangles();
    for(i = 1; i <= nbTriInFace; i++){
      // Get the triangle
      Standard_Integer N1,N2,N3;
      Triangles(i).Get(N1,N2,N3);
      N1 += aNbOfNodes - 1;
      N2 += aNbOfNodes - 1;
      N3 += aNbOfNodes - 1;
      vtkIdType anIds[3] = {N1, N2, N3};
      thePolyData->InsertNextCell(VTK_TRIANGLE,3,anIds);
    }
  } 
}
开发者ID:triggerfish1,项目名称:pythonocc,代码行数:43,代码来源:GEOM_ShadingFace.cpp


示例7: FromCascadeToChrono

void ChCascadeDoc::FromCascadeToChrono(const TopLoc_Location& from_coord, ChFrame<>& to_coord) {
    gp_XYZ mtr = from_coord.Transformation().TranslationPart();
    to_coord.SetPos(ChVector<>(mtr.X(), mtr.Y(), mtr.Z()));

    gp_Mat mro = from_coord.Transformation().VectorialPart();
    ChMatrix33<> to_mat;

    to_mat(0, 0) = mro(1, 1);
    to_mat(0, 1) = mro(1, 2);
    to_mat(0, 2) = mro(1, 3);

    to_mat(1, 0) = mro(2, 1);
    to_mat(1, 1) = mro(2, 2);
    to_mat(1, 2) = mro(2, 3);

    to_mat(2, 0) = mro(3, 1);
    to_mat(2, 1) = mro(3, 2);
    to_mat(2, 2) = mro(3, 3);

    to_coord.SetRot(to_mat);
}
开发者ID:armanpazouki,项目名称:chrono,代码行数:21,代码来源:ChCascadeDoc.cpp


示例8: OCCTesselation

OCCTesselation *OCCWire::tesselate(double angular, double curvature)
{
    OCCTesselation *ret = new OCCTesselation();
    try {
        Standard_Real start, end;
        OCCStruct3f dtmp;
        
        // explore wire edges in connected order
        int lastSize = 0;
        BRepTools_WireExplorer exWire;
        
        for (exWire.Init(this->getWire()); exWire.More(); exWire.Next()) {
            const TopoDS_Edge& edge = exWire.Current();
            TopLoc_Location loc = edge.Location();
            gp_Trsf location = loc.Transformation();
            
            const Handle(Geom_Curve)& curve = BRep_Tool::Curve(edge, start, end);
            const GeomAdaptor_Curve& aCurve(curve);
            
            GCPnts_TangentialDeflection TD(aCurve, start, end, angular, curvature);
            
            ret->ranges.push_back(ret->vertices.size());
            
            for (Standard_Integer i = 1; i <= TD.NbPoints(); i++)
            {
                gp_Pnt pnt = TD.Value(i).Transformed(location);
                dtmp.x = (float)pnt.X();
                dtmp.y = (float)pnt.Y();
                dtmp.z = (float)pnt.Z();
                ret->vertices.push_back(dtmp);
            }
            
            ret->ranges.push_back(ret->vertices.size() - lastSize);
            lastSize = ret->vertices.size();
        }
    } catch(Standard_Failure &err) {
        return NULL;
    }
    return ret;
}
开发者ID:Felipeasg,项目名称:occmodel,代码行数:40,代码来源:OCCWire.cpp


示例9: FromChronoToCascade

 void ChCascadeDoc::FromChronoToCascade(const ChFrame<>& from_coord, TopLoc_Location& to_coord)
{
	ChVector<> mpos = ((ChFrame<>&)from_coord).GetPos();
	gp_Vec mtr(mpos.x, mpos.y, mpos.z);

	ChMatrix33<>* from_mat = ((ChFrame<>&)from_coord).GetA();

	((gp_Trsf)(to_coord.Transformation()) ).SetValues( 
		 (*from_mat)(0,0) ,(*from_mat)(0,1), (*from_mat)(0,2), mpos.x ,
		 (*from_mat)(1,0) ,(*from_mat)(1,1), (*from_mat)(1,2), mpos.y ,
		 (*from_mat)(2,0) ,(*from_mat)(2,1), (*from_mat)(2,2), mpos.z ,
		 0,0);
}
开发者ID:saggita,项目名称:chrono,代码行数:13,代码来源:ChCascadeDoc.cpp


示例10: ForShape

	virtual bool ForShape(TopoDS_Shape& mshape, TopLoc_Location& mloc, char* mname, int mlevel, TDF_Label& mlabel)
	{
		for (int i=0; i<mlevel; i++) GetLog()<< "  ";
		GetLog() << "-Name :" << mname;
		
		if (mlevel==0) GetLog() << " (root)";
		GetLog() << "\n";

		for (int i=0; i<mlevel; i++) GetLog()<< "  ";
		gp_XYZ mtr = mloc.Transformation().TranslationPart();
		GetLog() << "      pos at: "<< mtr.X() <<" "<< mtr.Y() << " "<<mtr.Z() <<" (absolute) \n";
		for (int i=0; i<mlevel; i++) GetLog()<< "  ";
		gp_XYZ mtr2 = mshape.Location().Transformation().TranslationPart();
		GetLog() << "      pos at: "<< mtr2.X() <<" "<< mtr2.Y() << " "<<mtr2.Z() <<" (.Location)\n";

		return true;
	}
开发者ID:saggita,项目名称:chrono,代码行数:17,代码来源:ChCascadeDoc.cpp


示例11: edgeConstruct

void ShapeGeometryBuilder::edgeConstruct(const TopoDS_Edge &edgeIn)
{
  TopoDS_Face face = TopoDS::Face(edgeToFace.FindFromKey(edgeIn).First());
  if (face.IsNull())
    throw std::runtime_error("face is null in edge construction");

  TopLoc_Location location;
  Handle(Poly_Triangulation) triangulation;
  triangulation = BRep_Tool::Triangulation(face, location);

  const Handle(Poly_PolygonOnTriangulation) &segments =
      BRep_Tool::PolygonOnTriangulation(edgeIn, triangulation, location);
  if (segments.IsNull())
    throw std::runtime_error("edge triangulation is null in edge construction");

  gp_Trsf transformation;
  bool identity = true;
  if(!location.IsIdentity())
  {
    identity = false;
    transformation = location.Transformation();
  }

  const TColStd_Array1OfInteger& indexes = segments->Nodes();
  const TColgp_Array1OfPnt& nodes = triangulation->Nodes();
  osg::Vec3Array *vertices = dynamic_cast<osg::Vec3Array *>(edgeGeometry->getVertexArray());
  osg::Vec4Array *colors = dynamic_cast<osg::Vec4Array *>(edgeGeometry->getColorArray());
  osg::ref_ptr<osg::DrawElementsUInt> indices = new osg::DrawElementsUInt
	  (GL_LINE_STRIP, indexes.Length());
  osg::BoundingSphere bSphere;
  
  for (int index(indexes.Lower()); index < indexes.Upper() + 1; ++index)
  {
    gp_Pnt point = nodes(indexes(index));
    if(!identity)
	point.Transform(transformation);
    vertices->push_back(osg::Vec3(point.X(), point.Y(), point.Z()));
    colors->push_back(edgeGeometry->getColor());
    (*indices)[index - 1] = vertices->size() - 1;
    
    if (!bSphere.valid()) //for first one.
    {
      bSphere.center() = vertices->back();
      bSphere.radius() = 0.0;
    }
    else
      bSphere.expandBy(vertices->back());
  }
  edgeGeometry->addPrimitiveSet(indices.get());
  boost::uuids::uuid id = seerShape->findShapeIdRecord(edgeIn).id;
  std::size_t lastPrimitiveIndex = edgeGeometry->getNumPrimitiveSets() - 1;
  if (!idPSetWrapperEdge->hasId(id))
  {
    IdPSetRecord record;
    record.id = id;
    record.primitiveSetIndex = lastPrimitiveIndex;
    record.bSphere = bSphere;
    idPSetWrapperEdge->idPSetContainer.insert(record);
  }
  else
    //ensure that edges have the same primitive index between lod calls.
    //asserts here prior to having lod implemented is probably duplicate ids
    //for different geometry.
    assert(lastPrimitiveIndex == idPSetWrapperEdge->findPSetFromId(id));
}
开发者ID:blobfish,项目名称:cadseer,代码行数:65,代码来源:shapegeometry.cpp


示例12: copy

App::DocumentObjectExecReturn *Revolution::execute(void)
{
    App::DocumentObject* link = Sketch.getValue();
    if (!link)
        return new App::DocumentObjectExecReturn("No sketch linked");
    if (!link->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId()))
        return new App::DocumentObjectExecReturn("Linked object is not a Sketch or Part2DObject");

    Part::Part2DObject* pcSketch=static_cast<Part::Part2DObject*>(link);

    TopoDS_Shape shape = pcSketch->Shape.getShape()._Shape;
    if (shape.IsNull())
        return new App::DocumentObjectExecReturn("Linked shape object is empty");

    // this is a workaround for an obscure OCC bug which leads to empty tessellations
    // for some faces. Making an explicit copy of the linked shape seems to fix it.
    // The error only happens when re-computing the shape.
    if (!this->Shape.getValue().IsNull()) {
        BRepBuilderAPI_Copy copy(shape);
        shape = copy.Shape();
        if (shape.IsNull())
            return new App::DocumentObjectExecReturn("Linked shape object is empty");
    }

    TopExp_Explorer ex;
    std::vector<TopoDS_Wire> wires;
    for (ex.Init(shape, TopAbs_WIRE); ex.More(); ex.Next()) {
        wires.push_back(TopoDS::Wire(ex.Current()));
    }
    if (wires.empty()) // there can be several wires
        return new App::DocumentObjectExecReturn("Linked shape object is not a wire");

    // get the Sketch plane
    Base::Placement SketchPlm = pcSketch->Placement.getValue();

    // get reference axis
    App::DocumentObject *pcReferenceAxis = ReferenceAxis.getValue();
    const std::vector<std::string> &subReferenceAxis = ReferenceAxis.getSubValues();
    if (pcReferenceAxis && pcReferenceAxis == pcSketch) {
        bool hasValidAxis=false;
        Base::Axis axis;
        if (subReferenceAxis[0] == "V_Axis") {
            hasValidAxis = true;
            axis = pcSketch->getAxis(Part::Part2DObject::V_Axis);
        }
        else if (subReferenceAxis[0] == "H_Axis") {
            hasValidAxis = true;
            axis = pcSketch->getAxis(Part::Part2DObject::H_Axis);
        }
        else if (subReferenceAxis[0].size() > 4 && subReferenceAxis[0].substr(0,4) == "Axis") {
            int AxId = std::atoi(subReferenceAxis[0].substr(4,4000).c_str());
            if (AxId >= 0 && AxId < pcSketch->getAxisCount()) {
                hasValidAxis = true;
                axis = pcSketch->getAxis(AxId);
            }
        }
        if (hasValidAxis) {
            axis *= SketchPlm;
            Base::Vector3d base=axis.getBase();
            Base::Vector3d dir=axis.getDirection();
            Base.setValue(base.x,base.y,base.z);
            Axis.setValue(dir.x,dir.y,dir.z);
        }
    }

    // get revolve axis
    Base::Vector3f b = Base.getValue();
    gp_Pnt pnt(b.x,b.y,b.z);
    Base::Vector3f v = Axis.getValue();
    gp_Dir dir(v.x,v.y,v.z);

    // get the support of the Sketch if any
    App::DocumentObject* pcSupport = pcSketch->Support.getValue();
    Part::Feature *SupportObject = 0;
    if (pcSupport && pcSupport->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
        SupportObject = static_cast<Part::Feature*>(pcSupport);

    TopoDS_Shape aFace = makeFace(wires);
    if (aFace.IsNull())
        return new App::DocumentObjectExecReturn("Creating a face from sketch failed");

    // Rotate the face by half the angle to get revolution symmetric to sketch plane
    if (Midplane.getValue()) {
        gp_Trsf mov;
        mov.SetRotation(gp_Ax1(pnt, dir), Base::toRadians<double>(Angle.getValue()) * (-1.0) / 2.0);
        TopLoc_Location loc(mov);
        aFace.Move(loc);
    }

    this->positionBySketch();
    TopLoc_Location invObjLoc = this->getLocation().Inverted();
    pnt.Transform(invObjLoc.Transformation());
    dir.Transform(invObjLoc.Transformation());

    // Reverse angle if selected
    double angle = Base::toRadians<double>(Angle.getValue());
    if (Reversed.getValue() && !Midplane.getValue())
        angle *= (-1.0);

    try {
//.........这里部分代码省略.........
开发者ID:emagdalena,项目名称:FreeCAD,代码行数:101,代码来源:FeatureRevolution.cpp


示例13: faceConstruct

void ShapeGeometryBuilder::faceConstruct(const TopoDS_Face &faceIn)
{
  TopLoc_Location location;
  Handle(Poly_Triangulation) triangulation;
  triangulation = BRep_Tool::Triangulation(faceIn, location);

  if (triangulation.IsNull())
      throw std::runtime_error("null triangulation in face construction");

  bool signalOrientation(false);
  if (faceIn.Orientation() == TopAbs_FORWARD)
      signalOrientation = true;

  gp_Trsf transformation;
  bool identity = true;
  if(!location.IsIdentity())
  {
    identity = false;
    transformation = location.Transformation();
  }

  //vertices.
  const TColgp_Array1OfPnt& nodes = triangulation->Nodes();
  osg::Vec3Array *vertices = dynamic_cast<osg::Vec3Array *>(faceGeometry->getVertexArray());
  osg::Vec3Array *normals = dynamic_cast<osg::Vec3Array *>(faceGeometry->getNormalArray());
  osg::Vec4Array *colors = dynamic_cast<osg::Vec4Array *>(faceGeometry->getColorArray());
  std::size_t offset = vertices->size();
  for (int index(nodes.Lower()); index < nodes.Upper() + 1; ++index)
  {
    gp_Pnt point = nodes.Value(index);
    if(!identity)
	point.Transform(transformation);
    vertices->push_back(osg::Vec3(point.X(), point.Y(), point.Z()));
    normals->push_back(osg::Vec3(0.0, 0.0, 0.0));
    colors->push_back(faceGeometry->getColor());
  }

  const Poly_Array1OfTriangle& triangles = triangulation->Triangles();
  osg::ref_ptr<osg::DrawElementsUInt> indices = new osg::DrawElementsUInt
	  (GL_TRIANGLES, triangulation->NbTriangles() * 3);

  for (int index(triangles.Lower()); index < triangles.Upper() + 1; ++index)
  {
    int N1, N2, N3;
    triangles(index).Get(N1, N2, N3);

    int factor = (index - 1) * 3;
    if (!signalOrientation)
    {
      (*indices)[factor] = N3 - 1  + offset;
      (*indices)[factor + 1] = N2 - 1 + offset;
      (*indices)[factor + 2] = N1 - 1 + offset;
    }
    else
    {
      (*indices)[factor] = N1 - 1 + offset;
      (*indices)[factor + 1] = N2 - 1 + offset;
      (*indices)[factor + 2] = N3 - 1 + offset;
    }
    
    //store primitiveset index and vertex indes into map.
    PSetVertexRecord record;
    record.primitiveSetIndex = faceGeometry->getNumPrimitiveSets();
    
    record.vertexIndex = (*indices)[factor];
    pSetTriangleWrapper->pSetVertexContainer.insert(record);
    
    record.vertexIndex = (*indices)[factor + 1];
    pSetTriangleWrapper->pSetVertexContainer.insert(record);
    
    record.vertexIndex = (*indices)[factor + 2];
    pSetTriangleWrapper->pSetVertexContainer.insert(record);
    
    //now that we are combining faces into one geometry, osgUtil SmoothingVisitor
    //wants to 'average' out normals across faces. so we go back to manual calculation
    //of surface normals.

    osg::Vec3 pointOne(vertices->at((*indices)[factor]));
    osg::Vec3 pointTwo(vertices->at((*indices)[factor + 1]));
    osg::Vec3 pointThree(vertices->at((*indices)[factor + 2]));

    osg::Vec3 axisOne(pointTwo - pointOne);
    osg::Vec3 axisTwo(pointThree - pointOne);
    osg::Vec3 currentNormal(axisOne ^ axisTwo);
    if (currentNormal.isNaN())
	continue;
    currentNormal.normalize();

    osg::Vec3 tempNormal;

    tempNormal = (*normals)[(*indices)[factor]];
    tempNormal += currentNormal;
    tempNormal.normalize();
    (*normals)[(*indices)[factor]] = tempNormal;

    tempNormal = (*normals)[(*indices)[factor + 1]];
    tempNormal += currentNormal;
    tempNormal.normalize();
    (*normals)[(*indices)[factor + 1]] = tempNormal;

//.........这里部分代码省略.........
开发者ID:blobfish,项目名称:cadseer,代码行数:101,代码来源:shapegeometry.cpp


示例14: getSketchWires

App::DocumentObjectExecReturn *Revolution::execute(void)
{
    // Validate parameters
    double angle = Angle.getValue();
    if (angle < Precision::Confusion())
        return new App::DocumentObjectExecReturn("Angle of revolution too small");
    if (angle > 360.0)
        return new App::DocumentObjectExecReturn("Angle of revolution too large");

    angle = Base::toRadians<double>(angle);
    // Reverse angle if selected
    if (Reversed.getValue() && !Midplane.getValue())
        angle *= (-1.0);

    std::vector<TopoDS_Wire> wires;
    try {
        wires = getSketchWires();
    } catch (const Base::Exception& e) {
        return new App::DocumentObjectExecReturn(e.what());
    }

    TopoDS_Shape support;
    try {
        support = getSupportShape();
    } catch (const Base::Exception&) {
        // ignore, because support isn't mandatory
        support = TopoDS_Shape();
    }

    // update Axis from ReferenceAxis
    updateAxis();

    // get revolve axis
    Base::Vector3d b = Base.getValue();
    gp_Pnt pnt(b.x,b.y,b.z);
    Base::Vector3d v = Axis.getValue();
    gp_Dir dir(v.x,v.y,v.z);

    try {
        TopoDS_Shape sketchshape = makeFace(wires);
        if (sketchshape.IsNull())
            return new App::DocumentObjectExecReturn("Creating a face from sketch failed");

        // Rotate the face by half the angle to get Revolution symmetric to sketch plane
        if (Midplane.getValue()) {
            gp_Trsf mov;
            mov.SetRotation(gp_Ax1(pnt, dir), Base::toRadians<double>(Angle.getValue()) * (-1.0) / 2.0);
            TopLoc_Location loc(mov);
            sketchshape.Move(loc);
        }

        this->positionBySketch();
        TopLoc_Location invObjLoc = this->getLocation().Inverted();
        pnt.Transform(invObjLoc.Transformation());
        dir.Transform(invObjLoc.Transformation());
        support.Move(invObjLoc);
        sketchshape.Move(invObjLoc);

        // Check distance between sketchshape and axis - to avoid failures and crashes
        if (checkLineCrossesFace(gp_Lin(pnt, dir), TopoDS::Face(sketchshape)))
            return new App::DocumentObjectExecReturn("Revolve axis intersects the sketch");

        // revolve the face to a solid
        BRepPrimAPI_MakeRevol RevolMaker(sketchshape, gp_Ax1(pnt, dir), angle);

        if (RevolMaker.IsDone()) {
            TopoDS_Shape result = RevolMaker.Shape();
            result = refineShapeIfActive(result);
            // set the additive shape property for later usage in e.g. pattern
            this->AddShape.setValue(result);

            // if the sketch has a support fuse them to get one result object (PAD!)
            if (!support.IsNull()) {
                // Let's call algorithm computing a fuse operation:
                BRepAlgoAPI_Fuse mkFuse(support, result);
                // Let's check if the fusion has been successful
                if (!mkFuse.IsDone())
                    throw Base::Exception("Fusion with support failed");
                result = mkFuse.Shape();
                result = refineShapeIfActive(result);
            }

            this->Shape.setValue(result);
        }
        else
            return new App::DocumentObjectExecReturn("Could not revolve the sketch!");

        return App::DocumentObject::StdReturn;
    }
    catch (Standard_Failure) {
        Handle_Standard_Failure e = Standard_Failure::Caught();
        if (std::string(e->GetMessageString()) == "TopoDS::Face")
            return new App::DocumentObjectExecReturn("Could not create face from sketch.\n"
                "Intersecting sketch entities or multiple faces in a sketch are not allowed.");
        else
            return new App::DocumentObjectExecReturn(e->GetMessageString());
    }
    catch (Base::Exception& e) {
        return new App::DocumentObjectExecReturn(e.what());
    }
//.........这里部分代码省略.........
开发者ID:ADVALAIN596,项目名称:FreeCAD_sf_master,代码行数:101,代码来源:FeatureRevolution.cpp


示例15: recurse_CascadeDoc

static bool recurse_CascadeDoc(TDF_Label label,
                               Handle_XCAFDoc_ShapeTool& shapeTool,
                               TopLoc_Location& parentloc,
                               int level,
                               ChCascadeDoc::callback_CascadeDoc& mcallback) {
    TDF_LabelSequence child_labels;
    Standard_Boolean is_assembly;

    is_assembly = shapeTool->GetComponents(label, child_labels, 0);

    char mstring[200] = "no name";
    Standard_PCharacter mchastr = mstring;

    // access name
    Handle_TDataStd_Name N;
    if (label.FindAttribute(TDataStd_Name::GetID(), N)) {
        N->Get().ToUTF8CString(mchastr);
    }

    TDF_Label reflabel;
    Standard_Boolean isref = shapeTool->GetReferredShape(label, reflabel);

    if (isref)  // ..maybe it references some shape: the name is stored there...
    {
        Handle_TDataStd_Name N;
        if (reflabel.FindAttribute(TDataStd_Name::GetID(), N)) {
            N->Get().ToUTF8CString(mchastr);
        }
    }

    TopLoc_Location mloc = shapeTool->GetLocation(label);
    TopLoc_Location absloc = parentloc.Multiplied(mloc);

    // access shape and position
    TopoDS_Shape rShape;
    rShape = shapeTool->GetShape(label);
    if (!rShape.IsNull()) {
        // === call the callback! ===
        if (!mcallback.ForShape(rShape, absloc, mstring, level, label))
            return false;  // (skip children recursion if returned false)
    }

    // Recurse all children !!!
    if (is_assembly) {
        for (Standard_Integer j = 1; j <= child_labels.Length(); j++) {
            TDF_Label clabel = child_labels.Value(j);
            recurse_CascadeDoc(clabel, shapeTool, absloc, (level + 1), mcallback);
        }
    }

    // If it is a reference, Recurse all children of reference
    if (isref) {
        TDF_LabelSequence refchild_labels;
        Standard_Boolean refis_assembly;
        refis_assembly = shapeTool->GetComponents(reflabel, refchild_labels, 0);
        for (Standard_Integer j = 1; j <= refchild_labels.Length(); j++) {
            TDF_Label clabel = refchild_labels.Value(j);
            recurse_CascadeDoc(clabel, shapeTool, absloc, (level + 1), mcallback);
        }
    }

    return true;
}
开发者ID:armanpazouki,项目名称:chrono,代码行数:63,代码来源:ChCascadeDoc.cpp


示例16: getShape

App::DocumentObjectExecReturn *RuledSurface::execute(void)
{
    try {
        App::DocumentObjectExecReturn* ret;

        // get the first input shape
        TopoDS_Shape S1;
        ret = getShape(Curve1, S1);
        if (ret) return ret;

        // get the second input shape
        TopoDS_Shape S2;
        ret = getShape(Curve2, S2);
        if (ret) return ret;

        // check for expected type
        if (S1.IsNull() || S2.IsNull())
            return new App::DocumentObjectExecReturn("Linked shapes are empty.");

        if (S1.ShapeType() != TopAbs_EDGE && S1.ShapeType() != TopAbs_WIRE)
            return new App::DocumentObjectExecReturn("Linked shape is neither edge nor wire.");

        if (S2.ShapeType() != TopAbs_EDGE && S2.ShapeType() != TopAbs_WIRE)
            return new App::DocumentObjectExecReturn("Linked shape is neither edge nor wire.");

        // https://forum.freecadweb.org/viewtopic.php?f=8&t=24052
        //
        // if both shapes are sub-elements of one common shape then the fill algorithm
        // leads to problems if the shape has set a placement
        // The workaround is to reset the placement before calling BRepFill and then
        // applying the placement to the output shape
        TopLoc_Location Loc;
        if (Curve1.getValue() == Curve2.getValue()) {
            Loc = S1.Location();
            if (!Loc.IsIdentity() && Loc == S2.Location()) {
                S1.Location(TopLoc_Location());
                S2.Location(TopLoc_Location());
            }
        }

        // make both shapes to have the same type
        Standard_Boolean isWire = Standard_False;
        if (S1.ShapeType() == TopAbs_WIRE)
            isWire = Standard_True;

        if (isWire) {
            if (S2.ShapeType() == TopAbs_EDGE)
                S2 = BRepLib_MakeWire(TopoDS::Edge(S2));
        }
        else {
            // S1 is an edge, if S2 is a wire convert S1 to a wire, too
            if (S2.ShapeType() == TopAbs_WIRE) {
                S1 = BRepLib_MakeWire(TopoDS::Edge(S1));
                isWire = Standard_True;
            }
        }

        if (Orientation.getValue() == 0) {
            // Automatic
            Handle(Adaptor3d_HCurve) a1;
            Handle(Adaptor3d_HCurve) a2;
            if (!isWire) {
                BRepAdaptor_Curve adapt1(TopoDS::Edge(S1));
                BRepAdaptor_Curve adapt2(TopoDS::Edge(S2));
                a1 = new BRepAdaptor_HCurve(adapt1);
                a2 = new BRepAdaptor_HCurve(adapt2);
            }
            else {
                BRepAdaptor_CompCurve adapt1(TopoDS::Wire(S1));
                BRepAdaptor_CompCurve adapt2(TopoDS::Wire(S2));
                a1 = new BRepAdaptor_HCompCurve(adapt1);
                a2 = new BRepAdaptor_HCompCurve(adapt2);
            }

            if (!a1.IsNull() && !a2.IsNull()) {
                // get end points of 1st curve
                Standard_Real first, last;
                first = a1->FirstParameter();
                last = a1->LastParameter();
                if (S1.Closed())
                    last = (first + last)/2;
                gp_Pnt p1 = a1->Value(first);
                gp_Pnt p2 = a1->Value(last);
                if (S1.Orientation() == TopAbs_REVERSED) {
                    std::swap(p1, p2);
                }

                // get end points of 2nd curve
                first = a2->FirstParameter();
                last = a2->LastParameter();
                if (S2.Closed())
                    last = (first + last)/2;
                gp_Pnt p3 = a2->Value(first);
                gp_Pnt p4 = a2->Value(last);
                if (S2.Orientation() == TopAbs_REVERSED) {
                    std::swap(p3, p4);
                }

                // Form two triangles (P1,P2,P3) and (P4,P3,P2) and check their normals.
                // If the dot product is negative then it's assumed that the resulting face
//.........这里部分代码省略.........
开发者ID:frankhardy,项目名称:FreeCAD,代码行数:101,代码来源:PartFeatures.cpp


示例17: getVerifiedSketch

App::DocumentObjectExecReturn *Groove::execute(void)
{
    // Validate parameters
    double angle = Angle.getValue();
    if (angle < Precision::Confusion())
        return new App::DocumentObjectExecReturn("Angle of groove too small");
    if (angle > 360.0)
        return new App::DocumentObjectExecReturn("Angle of groove too large");

    angle = Base::toRadians<double>(angle);
    // Reverse angle if selected
    if (Reversed.getValue() && !Midplane.getValue())
        angle *= (-1.0);

    Part::Part2DObject* sketch = 0;
    std::vector<TopoDS_Wire> wires;
    TopoDS_Shape support;
    try {
        sketch = getVerifiedSketch();
        wires = getSketchWires();
        support = getSupportShape();
    } catch (const Base::Exception& e) {
        return new App::DocumentObjectExecReturn(e.what());
    }

    // get the Sketch plane
    Base::Placement SketchPlm = sketch->Placement.getValue();

    // get reference axis
    App::DocumentObject *pcReferenceAxis = ReferenceAxis.getValue();
    const std::vector<std::string> &subReferenceAxis = ReferenceAxis.getSubValues();
    if (pcReferenceAxis && pcReferenceAxis == sketch) {
        bool hasValidAxis=false;
        Base::Axis axis;
        if (subReferenceAxis[0] == "V_Axis") {
            hasValidAxis = true;
            axis = sketch->getAxis(Part::Part2DObject::V_Axis);
        }
        else if (subReferenceAxis[0] == "H_Axis") {
            hasValidAxis = true;
            axis = sketch->getAxis(Part::Part2DObject::H_Axis);
        }
        else if (subReferenceAxis[0].size() > 4 && subReferenceAxis[0].substr(0,4) == "Axis") {
            int AxId = std::atoi(subReferenceAxis[0].substr(4,4000).c_str());
            if (AxId >= 0 && AxId < sketch->getAxisCount()) {
                hasValidAxis = true;
                axis = sketch->getAxis(AxId);
            }
        }
        if (hasValidAxis) {
            axis *= SketchPlm;
            Base::Vector3d base=axis.getBase();
            Base::Vector3d dir=axis.getDirection();
            Base.setValue(base.x,base.y,base.z);
            Axis.setValue(dir.x,dir.y,dir.z);
        }
    }

    // get revolve axis
    Base::Vector3f b = Base.getValue();
    gp_Pnt pnt(b.x,b.y,b.z);
    Base::Vector3f v = Axis.getValue();
    gp_Dir dir(v.x,v.y,v.z);

    try {
        TopoDS_Shape sketchshape = makeFace(wires);
        if (sketchshape.IsNull())
            return new App::DocumentObjectExecReturn("Creating a face from sketch failed");

        // Rotate the face by half the angle to get Groove symmetric to sketch plane
        if (Midplane.getValue()) {
            gp_Trsf mov;
            mov.SetRotation(gp_Ax1(pnt, dir), Base::toRadians<double>(Angle.getValue()) * (-1.0) / 2.0);
            TopLoc_Location loc(mov);
            sketchshape.Move(loc);
        }

        this->positionBySketch();
        TopLoc_Location invObjLoc = this->getLocation().Inverted();
        pnt.Transform(invObjLoc.Transformation());
        dir.Transform(invObjLoc.Transformation());
        support.Move(invObjLoc);
        sketchshape.Move(invObjLoc);

        // Check distance between sketchshape and axis - to avoid failures and crashes
        if (checkLineCrossesFace(gp_Lin(pnt, dir), TopoDS::Face(sketchshape)))
            return new App::DocumentObjectExecReturn("Revolve axis intersects the sketch");

        // revolve the face to a solid
        BRepPrimAPI_MakeRevol RevolMaker(sketchshape, gp_Ax1(pnt, dir), angle);

        if (RevolMaker.IsDone()) {
            TopoDS_Shape result = RevolMaker.Shape();
            // set the subtractive shape property for later usage in e.g. pattern
            this->SubShape.setValue(result);

            // cut out groove to get one result object
            BRepAlgoAPI_Cut mkCut(support, result);
            // Let's check if the fusion has been successful
            if (!mkCut.IsDone())
//.........这里部分代码省略.........
开发者ID:Daedalus12,项目名称:FreeCAD_sf_master,代码行数:101,代码来源:FeatureGroove.cpp


示例18: getVerifiedSketch

App::DocumentObjectExecReturn *Pad::execute(void)
{
    // Validate parameters
    double L = Length.getValue();
    if ((std::string(Type.getValueAsString()) == "Length") && (L < Precision::Confusion()))
        return new App::DocumentObjectExecReturn("Length of pad too small");
    double L2 = Length2.getValue();
    if ((std::string(Type.getValueAsString()) == "TwoLengths") && (L < Precision::Confusion()))
        return new App::DocumentObjectExecReturn("Second length of pad too small");

    Part::Part2DObject* sketch = 0;
    std::vector<TopoDS_Wire> wires;
    try {
        sketch = getVerifiedSketch();
        wires = getSketchWires();
    } catch (const Base::Exception& e) {
        return new App::DocumentObjectExecReturn(e.what());
    }

    TopoDS_Shape support;
    try {
        support = getSupportShape();
    } catch (const Base::Exception&) {
        // ignore, because support isn't mandatory
        support = TopoDS_Shape();
    }

    // get the Sketch plane
    Base::Placement SketchPos = sketch->Placement.getValue();
    Base::Rotation SketchOrientation = SketchPos.getRotation();
    Base::Vector3d SketchVector(0,0,1);
    SketchOrientation.multVec(SketchVector,SketchVector);

    this->positionBySketch();
    TopLoc_Location invObjLoc = this->getLocation().Inverted();

    try {
        support.Move(invObjLoc);

        gp_Dir dir(SketchVector.x,SketchVector.y,SketchVector.z);
        dir.Transform(invObjLoc.Transformation());

        TopoDS_Shape sketchshape = makeFace(wires);
        if (sketchshape.IsNull())
            return new App::DocumentObjectExecReturn("Pad: Creating a face from sketch failed");
        sketchshape.Move(invObjLoc);

        TopoDS_Shape prism;
        std::string method(Type.getValueAsString());
        if (method == "UpToFirst" || method == "UpToLast" || method == "UpToFace") {
            TopoDS_Face supportface = getSupportFace();
            supportface.Move(invObjLoc);

            if (Reversed.getValue())
                dir.Reverse();

            // Find a valid face to extrude up to
            TopoDS_Face upToFace;
            if (method == "UpToFace") {
                getUpToFaceFromLinkSub(upToFace, UpToFace);
                upToFace.Move(invObjLoc);
            }
            getUpToFace(upToFace, support, supportface, sketchshape, method, dir);

            // A support object is always required and we need to use BRepFeat_MakePrism
            // Problem: For Pocket/UpToFirst (or an equivalent Pocket/UpToFace) the resulting shape is invalid
            // because the feature does not add any material. This only happens with the "2" option, though
            // Note: It might be possible to pass a shell or a compound containing multiple faces
            // as the Until parameter of Perform()
            BRepFeat_MakePrism PrismMaker;
            PrismMaker.Init(support, sketchshape, supportface, dir, 2, 1);
            PrismMaker.Perform(upToFace);

            if (!PrismMaker.IsDone())
                return new App::DocumentObjectExecReturn("Pad: Up to face: Could not extrude the sketch!");
            prism = PrismMaker.Shape();
        } else {
            generatePrism(prism, sketchshape, method, dir, L, L2,
                          Midplane.getValue(), Reversed.getValue());
        }

        if (prism.IsNull())
            return new App::DocumentObjectExecReturn("Pad: Resulting shape is empty");

        // set the additive shape property for later usage in e.g. pattern
        this->AddShape.setValue(prism);

        // if the sketch has a support fuse them to get one result object
        if (!support.IsNull()) {
            // Let's call algorithm computing a fuse operation:
            BRepAlgoAPI_Fuse mkFuse(support, prism);
            // Let's check if the fusion has been successful
            if (!mkFuse.IsDone())
                return new App::DocumentObjectExecReturn("Pad: Fusion with support failed");
            TopoDS_Shape result = mkFuse.Shape();
            // we have to get the solids (fuse sometimes creates compounds)
            TopoDS_Shape solRes = this->getSolid(result);
            // lets check if the result is a solid
            if (solRes.IsNull())
                return new App::DocumentObjectExecReturn("Pad: Resulting shape is not a solid");
//.........这里部分代码省略.........
开发者ID:c-lutaud,项目名称:FreeCAD_sf_master,代码行数:101,代码来源:FeaturePad.cpp


示例19: BRepBuilderAPI_MakeVertex

该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ TopSegmentIteratorConstPtr类代码示例发布时间:2022-05-31
下一篇:
C++ TopExp_Explorer类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap