本文整理汇总了C++中TopoDS_Shape::Move方法的典型用法代码示例。如果您正苦于以下问题:C++ TopoDS_Shape::Move方法的具体用法?C++ TopoDS_Shape::Move怎么用?C++ TopoDS_Shape::Move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TopoDS_Shape
的用法示例。
在下文中一共展示了TopoDS_Shape::Move方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
bool IfcGeom::Kernel::convert(const IfcSchema::IfcPolygonalBoundedHalfSpace* l, TopoDS_Shape& shape) {
TopoDS_Shape halfspace;
if ( ! IfcGeom::Kernel::convert((IfcSchema::IfcHalfSpaceSolid*)l,halfspace) ) return false;
TopoDS_Wire wire;
if ( ! convert_wire(l->PolygonalBoundary(),wire) || ! wire.Closed() ) return false;
gp_Trsf trsf;
if ( ! convert(l->Position(),trsf) ) return false;
TColgp_SequenceOfPnt points;
if (wire_to_sequence_of_point(wire, points)) {
remove_duplicate_points_from_loop(points, wire.Closed()); // Note: wire always closed, as per if statement above
remove_collinear_points_from_loop(points, wire.Closed());
sequence_of_point_to_wire(points, wire, wire.Closed());
}
TopoDS_Shape prism = BRepPrimAPI_MakePrism(BRepBuilderAPI_MakeFace(wire),gp_Vec(0,0,200));
gp_Trsf down; down.SetTranslation(gp_Vec(0,0,-100.0));
// `trsf` and `down` both have a unit scale factor
prism.Move(trsf*down);
shape = BRepAlgoAPI_Common(halfspace,prism);
return true;
}
示例2:
BldElement::BldElement(int id, string guid, string name, string type,
const IfcGeomObjects::IfcGeomShapeModelObject *o):id(id),guid(guid),name(name),type(type),geomtool(new Geometry){
BRep_Builder builder;
builder.MakeCompound(shape);
for (IfcGeom::IfcRepresentationShapeItems::const_iterator it = o->mesh().begin(); it != o->mesh().end(); ++ it) {
TopoDS_Shape brep = it->Shape();
gp_Trsf trsf = it->Placement().Trsf();
brep.Move(trsf);
// FIXME are the shells in the shape fixed by ifcopenshell?
builder.Add(shape,brep);
}
shape_original=shape;
}
示例3:
bool IfcGeom::Kernel::convert(const IfcSchema::IfcPolygonalBoundedHalfSpace* l, TopoDS_Shape& shape) {
TopoDS_Shape halfspace;
if ( ! IfcGeom::Kernel::convert((IfcSchema::IfcHalfSpaceSolid*)l,halfspace) ) return false;
TopoDS_Wire wire;
if ( ! convert_wire(l->PolygonalBoundary(),wire) || ! wire.Closed() ) return false;
gp_Trsf trsf;
convert(l->Position(),trsf);
TopoDS_Shape prism = BRepPrimAPI_MakePrism(BRepBuilderAPI_MakeFace(wire),gp_Vec(0,0,200));
gp_Trsf down; down.SetTranslation(gp_Vec(0,0,-100.0));
prism.Move(trsf*down);
shape = BRepAlgoAPI_Common(halfspace,prism);
return true;
}
示例4: exp
bool IfcGeom::Kernel::convert(const IfcSchema::IfcExtrudedAreaSolid* l, TopoDS_Shape& shape) {
const double height = l->Depth() * getValue(GV_LENGTH_UNIT);
if (height < getValue(GV_PRECISION)) {
Logger::Message(Logger::LOG_ERROR, "Non-positive extrusion height encountered for:", l->entity);
return false;
}
TopoDS_Shape face;
if ( !convert_face(l->SweptArea(),face) ) return false;
gp_Trsf trsf;
IfcGeom::Kernel::convert(l->Position(),trsf);
gp_Dir dir;
convert(l->ExtrudedDirection(),dir);
shape.Nullify();
if (face.ShapeType() == TopAbs_COMPOUND) {
// For compounds (most likely the result of a IfcCompositeProfileDef)
// create a compound solid shape.
TopExp_Explorer exp(face, TopAbs_FACE);
TopoDS_CompSolid compound;
BRep_Builder builder;
builder.MakeCompSolid(compound);
int num_faces_extruded = 0;
for (; exp.More(); exp.Next(), ++num_faces_extruded) {
builder.Add(compound, BRepPrimAPI_MakePrism(exp.Current(), height*dir));
}
if (num_faces_extruded) {
shape = compound;
}
}
if (shape.IsNull()) {
shape = BRepPrimAPI_MakePrism(face, height*dir);
}
// IfcSweptAreaSolid.Position (trsf) is an IfcAxis2Placement3D
// and therefore has a unit scale factor
shape.Move(trsf);
return ! shape.IsNull();
}
示例5: MakeWire
void BRepOffsetAPI_MakeOffsetFix::MakeWire(TopoDS_Shape& wire)
{
// get the edges of the wire and check which of the stored edges
// serve as input of the wire
TopTools_MapOfShape aMap;
TopExp_Explorer xp(wire, TopAbs_EDGE);
while (xp.More()) {
aMap.Add(xp.Current());
xp.Next();
}
std::list<TopoDS_Edge> edgeList;
for (auto itLoc : myLocations) {
const TopTools_ListOfShape& newShapes = mkOffset.Generated(itLoc.first);
for (TopTools_ListIteratorOfListOfShape it(newShapes); it.More(); it.Next()) {
TopoDS_Shape newShape = it.Value();
if (aMap.Contains(newShape)) {
newShape.Move(itLoc.second);
edgeList.push_back(TopoDS::Edge(newShape));
}
}
}
if (!edgeList.empty()) {
BRepBuilderAPI_MakeWire mkWire;
mkWire.Add(edgeList.front());
edgeList.pop_front();
wire = mkWire.Wire();
bool found = false;
do {
found = false;
for (std::list<TopoDS_Edge>::iterator pE = edgeList.begin(); pE != edgeList.end(); ++pE) {
mkWire.Add(*pE);
if (mkWire.Error() != BRepBuilderAPI_DisconnectedWire) {
// edge added ==> remove it from list
found = true;
edgeList.erase(pE);
wire = mkWire.Wire();
break;
}
}
}
while (found);
}
}
示例6: exp
bool IfcGeom::Kernel::convert(const IfcSchema::IfcSurfaceOfLinearExtrusion* l, TopoDS_Shape& shape) {
TopoDS_Wire wire;
if ( !convert_wire(l->SweptCurve(), wire) ) {
TopoDS_Face face;
if ( !convert_face(l->SweptCurve(),face) ) return false;
TopExp_Explorer exp(face, TopAbs_WIRE);
wire = TopoDS::Wire(exp.Current());
}
const double height = l->Depth() * getValue(GV_LENGTH_UNIT);
gp_Trsf trsf;
IfcGeom::Kernel::convert(l->Position(),trsf);
gp_Dir dir;
convert(l->ExtrudedDirection(),dir);
shape = BRepPrimAPI_MakePrism(wire, height*dir);
shape.Move(trsf);
return !shape.IsNull();
}
示例7: getValue
bool IfcGeom::Kernel::convert(const IfcSchema::IfcRevolvedAreaSolid* l, TopoDS_Shape& shape) {
const double ang = l->Angle() * getValue(GV_PLANEANGLE_UNIT);
TopoDS_Face face;
if ( ! convert_face(l->SweptArea(),face) ) return false;
gp_Ax1 ax1;
IfcGeom::Kernel::convert(l->Axis(), ax1);
gp_Trsf trsf;
IfcGeom::Kernel::convert(l->Position(),trsf);
if (ang >= M_PI * 2. - ALMOST_ZERO) {
shape = BRepPrimAPI_MakeRevol(face, ax1);
} else {
shape = BRepPrimAPI_MakeRevol(face, ax1, ang);
}
shape.Move(trsf);
return !shape.IsNull();
}
示例8: DocumentObjectExecReturn
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");
//.........这里部分代码省略.........
示例9: DocumentObjectExecReturn
App::DocumentObjectExecReturn *Pipe::execute(void)
{
std::vector<TopoDS_Wire> wires;
try {
wires = getProfileWires();
} catch (const Base::Exception& e) {
return new App::DocumentObjectExecReturn(e.what());
}
TopoDS_Shape sketchshape = getVerifiedFace();
if (sketchshape.IsNull())
return new App::DocumentObjectExecReturn("Pipe: No valid sketch or face as first section");
else {
//TODO: currently we only allow planar faces. the reason for this is that with other faces in front, we could
//not use the current simulate approach and build the start and end face from the wires. As the shell
//beginns always at the spine and not the profile, the sketchshape cannot be used directly as front face.
//We would need a method to translate the frontshape to match the shell starting position somehow...
TopoDS_Face face = TopoDS::Face(sketchshape);
BRepAdaptor_Surface adapt(face);
if(adapt.GetType() != GeomAbs_Plane)
return new App::DocumentObjectExecReturn("Pipe: Only planar faces supportet");
}
// if the Base property has a valid shape, fuse the pipe into it
TopoDS_Shape base;
try {
base = getBaseShape();
} catch (const Base::Exception&) {
base = TopoDS_Shape();
}
try {
//setup the location
this->positionByPrevious();
TopLoc_Location invObjLoc = this->getLocation().Inverted();
if(!base.IsNull())
base.Move(invObjLoc);
//build the paths
App::DocumentObject* spine = Spine.getValue();
if (!(spine && spine->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())))
return new App::DocumentObjectExecReturn("No spine linked.");
std::vector<std::string> subedge = Spine.getSubValues();
TopoDS_Shape path;
const Part::TopoShape& shape = static_cast<Part::Feature*>(spine)->Shape.getValue();
buildPipePath(shape, subedge, path);
path.Move(invObjLoc);
TopoDS_Shape auxpath;
if(Mode.getValue()==3) {
App::DocumentObject* auxspine = AuxillerySpine.getValue();
if (!(auxspine && auxspine->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())))
return new App::DocumentObjectExecReturn("No auxillery spine linked.");
std::vector<std::string> auxsubedge = AuxillerySpine.getSubValues();
TopoDS_Shape path;
const Part::TopoShape& auxshape = static_cast<Part::Feature*>(auxspine)->Shape.getValue();
buildPipePath(auxshape, auxsubedge, auxpath);
auxpath.Move(invObjLoc);
}
//build up multisections
auto multisections = Sections.getValues();
std::vector<std::vector<TopoDS_Wire>> wiresections;
for(TopoDS_Wire& wire : wires)
wiresections.push_back(std::vector<TopoDS_Wire>(1, wire));
//maybe we need a sacling law
Handle(Law_Function) scalinglaw;
//see if we shall use multiple sections
if(Transformation.getValue() == 1) {
//TODO: we need to order the sections to prevent occ from crahsing, as makepieshell connects
//the sections in the order of adding
for(App::DocumentObject* obj : multisections) {
if(!obj->isDerivedFrom(Part::Feature::getClassTypeId()))
return new App::DocumentObjectExecReturn("All sections need to be part features");
TopExp_Explorer ex;
size_t i=0;
for (ex.Init(static_cast<Part::Feature*>(obj)->Shape.getValue(), TopAbs_WIRE); ex.More(); ex.Next()) {
wiresections[i].push_back(TopoDS::Wire(ex.Current()));
if(i>=wiresections.size())
return new App::DocumentObjectExecReturn("Multisections need to have the same amount of inner wires as the base section");
++i;
}
if(i<wiresections.size())
return new App::DocumentObjectExecReturn("Multisections need to have the same amount of inner wires as the base section");
}
}
/*//build the law functions instead
else if(Transformation.getValue() == 2) {
if(ScalingData.getValues().size()<1)
return new App::DocumentObjectExecReturn("No valid data given for liinear scaling mode");
Handle(Law_Linear) lin = new Law_Linear();
//.........这里部分代码省略.........
示例10: DocumentObjectExecReturn
//.........这里部分代码省略.........
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
// is twisted, hence the 2nd edge is reversed.
gp_Vec v1(p1, p2);
gp_Vec v2(p1, p3);
gp_Vec n1 = v1.Crossed(v2);
gp_Vec v3(p4, p3);
gp_Vec v4(p4, p2);
gp_Vec n2 = v3.Crossed(v4);
if (n1.Dot(n2) < 0) {
S2.Reverse();
}
}
}
else if (Orientation.getValue() == 2) {
// Reverse
S2.Reverse();
}
TopoDS_Shape ruledShape;
if (!isWire) {
ruledShape = BRepFill::Face(TopoDS::Edge(S1), TopoDS::Edge(S2));
}
else {
ruledShape = BRepFill::Shell(TopoDS::Wire(S1), TopoDS::Wire(S2));
}
// re-apply the placement in case we reset it
if (!Loc.IsIdentity())
ruledShape.Move(Loc);
Loc = ruledShape.Location();
if (!Loc.IsIdentity()) {
// reset the placement of the shape because the Placement
// property will be changed
ruledShape.Location(TopLoc_Location());
Base::Matrix4D transform;
TopoShape::convertToMatrix(Loc.Transformation(), transform);
this->Placement.setValue(Base::Placement(transform));
}
this->Shape.setValue(ruledShape);
return App::DocumentObject::StdReturn;
}
catch (Standard_Failure& e) {
return new App::DocumentObjectExecReturn(e.GetMessageString());
}
catch (...) {
return new App::DocumentObjectExecReturn("General error in RuledSurface::execute()");
}
}
示例11: DocumentObjectExecReturn
App::DocumentObjectExecReturn *Loft::execute(void)
{
std::vector<TopoDS_Wire> wires;
try {
wires = getProfileWires();
} catch (const Base::Exception& e) {
return new App::DocumentObjectExecReturn(e.what());
}
TopoDS_Shape sketchshape = getVerifiedFace();
if (sketchshape.IsNull())
return new App::DocumentObjectExecReturn("Loft: Creating a face from sketch failed");
// if the Base property has a valid shape, fuse the pipe into it
TopoDS_Shape base;
try {
base = getBaseShape();
} catch (const Base::Exception&) {
base = TopoDS_Shape();
}
try {
//setup the location
this->positionByPrevious();
TopLoc_Location invObjLoc = this->getLocation().Inverted();
if(!base.IsNull())
base.Move(invObjLoc);
//build up multisections
auto multisections = Sections.getValues();
if(multisections.empty())
return new App::DocumentObjectExecReturn("Loft: At least one section is needed");
std::vector<std::vector<TopoDS_Wire>> wiresections;
for(TopoDS_Wire& wire : wires)
wiresections.push_back(std::vector<TopoDS_Wire>(1, wire));
for(App::DocumentObject* obj : multisections) {
if(!obj->isDerivedFrom(Part::Feature::getClassTypeId()))
return new App::DocumentObjectExecReturn("Loft: All sections need to be part features");
TopExp_Explorer ex;
size_t i=0;
for (ex.Init(static_cast<Part::Feature*>(obj)->Shape.getValue(), TopAbs_WIRE); ex.More(); ex.Next(), ++i) {
if(i>=wiresections.size())
return new App::DocumentObjectExecReturn("Loft: Sections need to have the same amount of inner wires as the base section");
wiresections[i].push_back(TopoDS::Wire(ex.Current()));
}
if(i<wiresections.size())
return new App::DocumentObjectExecReturn("Loft: Sections need to have the same amount of inner wires as the base section");
}
//build all shells
std::vector<TopoDS_Shape> shells;
for(std::vector<TopoDS_Wire>& wires : wiresections) {
BRepOffsetAPI_ThruSections mkTS(false, Ruled.getValue(), Precision::Confusion());
for(TopoDS_Wire& wire : wires) {
wire.Move(invObjLoc);
mkTS.AddWire(wire);
}
mkTS.Build();
if (!mkTS.IsDone())
return new App::DocumentObjectExecReturn("Loft could not be build");
//build the shell use simulate to get the top and bottom wires in an easy way
shells.push_back(mkTS.Shape());
}
//build the top and bottom face, sew the shell and build the final solid
TopoDS_Shape front = getVerifiedFace();
front.Move(invObjLoc);
std::vector<TopoDS_Wire> backwires;
for(std::vector<TopoDS_Wire>& wires : wiresections)
backwires.push_back(wires.back());
TopoDS_Shape back = Part::FaceMakerCheese::makeFace(backwires);
BRepBuilderAPI_Sewing sewer;
sewer.SetTolerance(Precision::Confusion());
sewer.Add(front);
sewer.Add(back);
for(TopoDS_Shape& s : shells)
sewer.Add(s);
sewer.Perform();
//build the solid
BRepBuilderAPI_MakeSolid mkSolid;
mkSolid.Add(TopoDS::Shell(sewer.SewedShape()));
if(!mkSolid.IsDone())
return new App::DocumentObjectExecReturn("Loft: Result is not a solid");
TopoDS_Shape result = mkSolid.Shape();
BRepClass3d_SolidClassifier SC(result);
SC.PerformInfinitePoint(Precision::Confusion());
//.........这里部分代码省略.........
示例12: DummyHP
//.........这里部分代码省略.........
}
case circle :
{
Standard_Boolean sense = Standard_True;
if (radius < 0) {
radius = -radius;
sense = !sense;
dx = -dx;
dy = -dy;
}
gp_Ax2d ax(gp_Pnt2d(x-radius*dy,y+radius*dx),gp_Dir2d(dy,-dx));
if (angle < 0) {
angle = -angle;
sense = !sense;
}
Handle(Geom2d_Circle) c = new Geom2d_Circle(ax,radius,sense);
BRepBuilderAPI_MakeEdge ME (GeomAPI::To3d(c,P),0,angle);
if (!ME.IsDone())
return;
MW.Add(ME);
gp_Pnt2d p;
gp_Vec2d v;
c->D1(angle,p,v);
x = p.X();
y = p.Y();
dx = v.X() / radius;
dy = v.Y() / radius;
break;
}
case point:
{
MP = BRepBuilderAPI_MakeVertex(gp_Pnt(x, y, 0.0));
break;
}
case none:
{
i = n - 1;
break;
}
}
// update first
first = stayfirst;
stayfirst = Standard_False;
if(!(dx == 0 && dy == 0))
myLastDir.SetCoord(dx, dy, 0.0);
else
return;
myLastPoint.SetX(x);
myLastPoint.SetY(y);
// next segment....
i++;
if ((i == n) && close) {
// the closing segment
dx = x0 - x;
dy = y0 - y;
length = Sqrt(dx * dx + dy * dy);
move = line;
if (length > Precision::Confusion()) {
dx = dx / length;
dy = dy / length;
goto again;
}
}
}
// get the result, face or wire
if (move == none) {
return;
} else if (move == point) {
S = MP;
} else if (face) {
if (!MW.IsDone()) {
return;
}
BRepBuilderAPI_MakeFace MF (P, MW.Wire());
if (!MF.IsDone()) {
return;
}
S = MF;
} else {
if (!MW.IsDone()) {
return;
}
S = MW;
}
if(!TheLocation.IsIdentity())
S.Move(TheLocation);
myShape = S;
myOK = true;
return;
badargs :
MESSAGE("profile : bad number of arguments");
return;
}
示例13: DocumentObjectExecReturn
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())
//.........这里部分代码省略.........
示例14: DocumentObjectExecReturn
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());
}
//.........这里部分代码省略.........
示例15: extrudeShape
TopoShape Extrusion::extrudeShape(const TopoShape source, Extrusion::ExtrusionParameters params)
{
TopoDS_Shape result;
gp_Vec vec = gp_Vec(params.dir).Multiplied(params.lengthFwd+params.lengthRev);//total vector of extrusion
if (std::fabs(params.taperAngleFwd) >= Precision::Angular() ||
std::fabs(params.taperAngleRev) >= Precision::Angular() ) {
//Tapered extrusion!
#if defined(__GNUC__) && defined (FC_OS_LINUX)
Base::SignalException se;
#endif
TopoDS_Shape myShape = source.getShape();
if (myShape.IsNull())
Standard_Failure::Raise("Cannot extrude empty shape");
// #0000910: Circles Extrude Only Surfaces, thus use BRepBuilderAPI_Copy
myShape = BRepBuilderAPI_Copy(myShape).Shape();
std::list<TopoDS_Shape> drafts;
makeDraft(params, myShape, drafts);
if (drafts.empty()) {
Standard_Failure::Raise("Drafting shape failed");
}
else if (drafts.size() == 1) {
result = drafts.front();
}
else {
TopoDS_Compound comp;
BRep_Builder builder;
builder.MakeCompound(comp);
for (std::list<TopoDS_Shape>::iterator it = drafts.begin(); it != drafts.end(); ++it)
builder.Add(comp, *it);
result = comp;
}
}
else {
//Regular (non-tapered) extrusion!
TopoDS_Shape myShape = source.getShape();
if (myShape.IsNull())
Standard_Failure::Raise("Cannot extrude empty shape");
// #0000910: Circles Extrude Only Surfaces, thus use BRepBuilderAPI_Copy
myShape = BRepBuilderAPI_Copy(myShape).Shape();
//apply reverse part of extrusion by shifting the source shape
if (fabs(params.lengthRev)>Precision::Confusion() ){
gp_Trsf mov;
mov.SetTranslation(gp_Vec(params.dir)*(-params.lengthRev));
TopLoc_Location loc(mov);
myShape.Move(loc);
}
//make faces from wires
if (params.solid) {
//test if we need to make faces from wires. If there are faces - we don't.
TopExp_Explorer xp(myShape, TopAbs_FACE);
if (xp.More()){
//source shape has faces. Just extrude as-is.
} else {
std::unique_ptr<FaceMaker> mkFace = FaceMaker::ConstructFromType(params.faceMakerClass.c_str());
if (myShape.ShapeType() == TopAbs_COMPOUND)
mkFace->useCompound(TopoDS::Compound(myShape));
else
mkFace->addShape(myShape);
mkFace->Build();
myShape = mkFace->Shape();
}
}
//extrude!
BRepPrimAPI_MakePrism mkPrism(myShape, vec);
result = mkPrism.Shape();
}
if (result.IsNull())
throw Base::Exception("Result of extrusion is null shape.");
return TopoShape(result);
}