本文整理汇总了C++中TopoDS_Face::IsNull方法的典型用法代码示例。如果您正苦于以下问题:C++ TopoDS_Face::IsNull方法的具体用法?C++ TopoDS_Face::IsNull怎么用?C++ TopoDS_Face::IsNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TopoDS_Face
的用法示例。
在下文中一共展示了TopoDS_Face::IsNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetNodeUVneedInFaceNode
bool SMESH_MesherHelper::GetNodeUVneedInFaceNode(const TopoDS_Face& F) const
{
if ( F.IsNull() ) return !mySeamShapeIds.empty();
if ( !F.IsNull() && !myShape.IsNull() && myShape.IsSame( F ))
return !mySeamShapeIds.empty();
Handle(Geom_Surface) aSurface = BRep_Tool::Surface( F );
if ( !aSurface.IsNull() )
return ( aSurface->IsUPeriodic() || aSurface->IsVPeriodic() );
return false;
}
示例2: getSupportFace
// TODO: This code is taken from and duplicates code in Part2DObject::positionBySupport()
// Note: We cannot return a reference, because it will become Null.
// Not clear where, because we check for IsNull() here, but as soon as it is passed out of
// this method, it becomes null!
const TopoDS_Face SketchBased::getSupportFace() const {
const App::PropertyLinkSub& Support = static_cast<Part::Part2DObject*>(Sketch.getValue())->Support;
Part::Feature *part = static_cast<Part::Feature*>(Support.getValue());
if (!part || !part->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
throw Base::Exception("Sketch has no support shape");
const std::vector<std::string> &sub = Support.getSubValues();
assert(sub.size()==1);
// get the selected sub shape (a Face)
const Part::TopoShape &shape = part->Shape.getShape();
if (shape._Shape.IsNull())
throw Base::Exception("Sketch support shape is empty!");
TopoDS_Shape sh = shape.getSubShape(sub[0].c_str());
if (sh.IsNull())
throw Base::Exception("Null shape in SketchBased::getSupportFace()!");
const TopoDS_Face face = TopoDS::Face(sh);
if (face.IsNull())
throw Base::Exception("Null face in SketchBased::getSupportFace()!");
BRepAdaptor_Surface adapt(face);
if (adapt.GetType() != GeomAbs_Plane)
throw Base::Exception("No planar face in SketchBased::getSupportFace()!");
return face;
}
示例3: GetFaceNormalAtUV
gp_Dir GetFaceNormalAtUV(const TopoDS_Face &face, double u, double v, gp_Pnt *pos){
if(face.IsNull()) return gp_Dir(0, 0, 1);
try
{
Handle(Geom_Surface) surf=BRep_Tool::Surface(face); // get surface properties
GeomLProp_SLProps props(surf, u, v, 1, 0.01); // get surface normal
if(!props.IsNormalDefined())return gp_Dir(0, 0, 1);
gp_Dir norm=props.Normal(); // check orientation
if(pos)*pos = props.Value();
if(face.Orientation()==TopAbs_REVERSED) norm.Reverse();
return norm;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
wxMessageBox(wxString(_("Error in GetFaceNormalAtUV")) + _T(": ") + Ctt(e->GetMessageString()));
return gp_Dir(0, 0, 1);
}
catch (const char* str)
{
wxMessageBox(wxString(_("Error in GetFaceNormalAtUV")) + _T(": ") + Ctt(str));
return gp_Dir(0, 0, 1);
}
catch (...)
{
wxMessageBox(_("Error in GetFaceNormalAtUV"));
return gp_Dir(0, 0, 1);
}
}
示例4: prepare
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();
}
示例5: buildFace
TopoDS_Face FaceTypedCylinder::buildFace(const FaceVectorType &faces) const
{
std::vector<EdgeVectorType> boundaries;
boundarySplit(faces, boundaries);
static TopoDS_Face dummy;
if (boundaries.size() < 1)
return dummy;
//take one face and remove all the wires.
TopoDS_Face workFace = faces.at(0);
ShapeBuild_ReShape reshaper;
TopExp_Explorer it;
for (it.Init(workFace, TopAbs_WIRE); it.More(); it.Next())
reshaper.Remove(it.Current());
workFace = TopoDS::Face(reshaper.Apply(workFace));
if (workFace.IsNull())
return TopoDS_Face();
ShapeFix_Face faceFixer(workFace);
//makes wires
std::vector<EdgeVectorType>::iterator boundaryIt;
for (boundaryIt = boundaries.begin(); boundaryIt != boundaries.end(); ++boundaryIt)
{
BRepLib_MakeWire wireMaker;
EdgeVectorType::iterator it;
for (it = (*boundaryIt).begin(); it != (*boundaryIt).end(); ++it)
wireMaker.Add(*it);
if (wireMaker.Error() != BRepLib_WireDone)
continue;
faceFixer.Add(wireMaker.Wire());
}
if (faceFixer.Perform() > ShapeExtend_DONE5)
return TopoDS_Face();
faceFixer.FixOrientation();
if (faceFixer.Perform() > ShapeExtend_DONE5)
return TopoDS_Face();
return faceFixer.Face();
}
示例6: Exception
const std::list<gp_Trsf> LinearPattern::getTransformations(const std::vector<App::DocumentObject*>)
{
std::string stdDirection = StdDirection.getValue();
float distance = Length.getValue();
if (distance < Precision::Confusion())
throw Base::Exception("Pattern length too small");
int occurrences = Occurrences.getValue();
if (occurrences < 2)
throw Base::Exception("At least two occurrences required");
bool reversed = Reversed.getValue();
gp_Dir dir;
double offset = distance / (occurrences - 1);
if (!stdDirection.empty()) {
// Note: The placement code commented out below had the defect of working always on the
// absolute X,Y,Z direction, not on the relative coordinate system of the Body feature.
// It requires positionBySupport() to be called in Transformed::Execute() AFTER
// the call to getTransformations()
// New code thanks to logari81
if (stdDirection == "X") {
//dir = Base::Axis(Base::Vector3d(0,0,0), Base::Vector3d(1,0,0));
dir = gp_Dir(1,0,0);
} else if (stdDirection == "Y") {
//dir = Base::Axis(Base::Vector3d(0,0,0), Base::Vector3d(0,1,0));
dir = gp_Dir(0,1,0);
} else if(stdDirection == "Z") {
//dir = Base::Axis(Base::Vector3d(0,0,0), Base::Vector3d(0,0,1));
dir = gp_Dir(0,0,1);
} else {
throw Base::Exception("Invalid direction (must be X, Y or Z)");
}
} else {
App::DocumentObject* refObject = Direction.getValue();
if (refObject == NULL)
throw Base::Exception("No direction specified");
if (!refObject->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
throw Base::Exception("Direction reference must be edge or face of a feature");
std::vector<std::string> subStrings = Direction.getSubValues();
if (subStrings.empty() || subStrings[0].empty())
throw Base::Exception("No direction reference specified");
Part::Feature* refFeature = static_cast<Part::Feature*>(refObject);
Part::TopoShape refShape = refFeature->Shape.getShape();
TopoDS_Shape ref = refShape.getSubShape(subStrings[0].c_str());
if (ref.ShapeType() == TopAbs_FACE) {
TopoDS_Face refFace = TopoDS::Face(ref);
if (refFace.IsNull())
throw Base::Exception("Failed to extract direction plane");
BRepAdaptor_Surface adapt(refFace);
if (adapt.GetType() != GeomAbs_Plane)
throw Base::Exception("Direction face must be planar");
dir = adapt.Plane().Axis().Direction();
//gp_Dir d = adapt.Plane().Axis().Direction();
//dir = Base::Axis(Base::Vector3d(0,0,0), Base::Vector3d(d.X(), d.Y(), d.Z()));
} else if (ref.ShapeType() == TopAbs_EDGE) {
TopoDS_Edge refEdge = TopoDS::Edge(ref);
if (refEdge.IsNull())
throw Base::Exception("Failed to extract direction edge");
BRepAdaptor_Curve adapt(refEdge);
if (adapt.GetType() != GeomAbs_Line)
throw Base::Exception("Direction edge must be a straight line");
//gp_Dir d = adapt.Line().Direction();
//dir = Base::Axis(Base::Vector3d(0,0,0), Base::Vector3d(d.X(), d.Y(), d.Z()));
dir = adapt.Line().Direction();
} else {
throw Base::Exception("Direction reference must be edge or face");
}
TopLoc_Location invObjLoc = this->getLocation().Inverted();
dir.Transform(invObjLoc.Transformation());
}
// get the support placement
// TODO: Check for NULL pointer
/*Part::Feature* supportFeature = static_cast<Part::Feature*>(originals.front());
if (supportFeature == NULL)
throw Base::Exception("Cannot work on invalid support shape");
Base::Placement supportPlacement = supportFeature->Placement.getValue();
dir *= supportPlacement;
gp_Vec direction(dir.getDirection().x, dir.getDirection().y, dir.getDirection().z);*/
gp_Vec direction(dir.X(), dir.Y(), dir.Z());
if (reversed)
direction.Reverse();
// Note: The original feature is NOT included in the list of transformations! Therefore
// we start with occurrence number 1, not number 0
std::list<gp_Trsf> transformations;
gp_Trsf trans;
transformations.push_back(trans); // identity transformation
for (int i = 1; i < occurrences; i++) {
trans.SetTranslation(direction * i * offset);
transformations.push_back(trans);
}
return transformations;
//.........这里部分代码省略.........
示例7: Compute
//.........这里部分代码省略.........
nbSeg = nbFac = nbVol = isOK = 0;
break;
}
nodeVec.at(i) = node;
if (newNodeOnVertex)
{
// point on vertex
meshDS->SetNodeOnVertex(node, aVert);
pindMap.Add(i);
}
}
// create mesh segments along geometric edges
NCollection_Map<Link> linkMap;
for (i = nbInitSeg+1; i <= nbSeg/* && isOK*/; ++i )
{
const netgen::Segment& seg = ngMesh->LineSegment(i);
Link link(seg.p1, seg.p2);
if (linkMap.Contains(link))
continue;
linkMap.Add(link);
TopoDS_Edge aEdge;
int pinds[3] = { seg.p1, seg.p2, seg.pmid };
int nbp = 0;
double param2 = 0;
for (int j=0; j < 3; ++j)
{
int pind = pinds[j];
if (pind <= 0) continue;
++nbp;
double param;
if (j < 2)
{
if (aEdge.IsNull())
{
int aGeomEdgeInd = seg.epgeominfo[j].edgenr;
if (aGeomEdgeInd > 0 && aGeomEdgeInd <= occgeo.emap.Extent())
aEdge = TopoDS::Edge(occgeo.emap(aGeomEdgeInd));
}
param = seg.epgeominfo[j].dist;
param2 += param;
}
else
param = param2 * 0.5;
if (pind <= nbInitNod || pindMap.Contains(pind))
continue;
if (!aEdge.IsNull())
{
meshDS->SetNodeOnEdge(nodeVec.at(pind), aEdge, param);
pindMap.Add(pind);
}
}
SMDS_MeshEdge* edge;
if (nbp < 3) // second order ?
edge = meshDS->AddEdge(nodeVec.at(pinds[0]), nodeVec.at(pinds[1]));
else
edge = meshDS->AddEdge(nodeVec.at(pinds[0]), nodeVec.at(pinds[1]),
nodeVec.at(pinds[2]));
if (!edge)
{
if ( !comment.size() ) comment << "Cannot create a mesh edge";
MESSAGE("Cannot create a mesh edge");
nbSeg = nbFac = nbVol = isOK = 0;
break;
}
if (!aEdge.IsNull())
示例8: 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));
}
示例9: execute
App::DocumentObjectExecReturn *DrawViewSection::execute(void)
{
App::DocumentObject* link = Source.getValue();
App::DocumentObject* base = BaseView.getValue();
if (!link || !base) {
Base::Console().Log("INFO - DVS::execute - No Source or Link - creation?\n");
return DrawView::execute();
}
if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
return new App::DocumentObjectExecReturn("Source object is not a Part object");
if (!base->getTypeId().isDerivedFrom(TechDraw::DrawViewPart::getClassTypeId()))
return new App::DocumentObjectExecReturn("BaseView object is not a DrawViewPart object");
//Base::Console().Message("TRACE - DVS::execute() - %s/%s\n",getNameInDocument(),Label.getValue());
const Part::TopoShape &partTopo = static_cast<Part::Feature*>(link)->Shape.getShape();
if (partTopo.getShape().IsNull())
return new App::DocumentObjectExecReturn("Linked shape object is empty");
(void) DrawView::execute(); //make sure Scale is up to date
gp_Pln pln = getSectionPlane();
gp_Dir gpNormal = pln.Axis().Direction();
Base::Vector3d orgPnt = SectionOrigin.getValue();
Base::BoundBox3d bb = partTopo.getBoundBox();
if(!isReallyInBox(orgPnt, bb)) {
Base::Console().Warning("DVS: Section Plane doesn't intersect part in %s\n",getNameInDocument());
Base::Console().Warning("DVS: Using center of bounding box.\n");
orgPnt = bb.GetCenter();
SectionOrigin.setValue(orgPnt);
}
// Make the extrusion face
double dMax = bb.CalcDiagonalLength();
BRepBuilderAPI_MakeFace mkFace(pln, -dMax,dMax,-dMax,dMax);
TopoDS_Face aProjFace = mkFace.Face();
if(aProjFace.IsNull())
return new App::DocumentObjectExecReturn("DrawViewSection - Projected face is NULL");
gp_Vec extrudeDir = dMax * gp_Vec(gpNormal);
TopoDS_Shape prism = BRepPrimAPI_MakePrism(aProjFace, extrudeDir, false, true).Shape();
// We need to copy the shape to not modify the BRepstructure
BRepBuilderAPI_Copy BuilderCopy(partTopo.getShape());
TopoDS_Shape myShape = BuilderCopy.Shape();
BRepAlgoAPI_Cut mkCut(myShape, prism);
if (!mkCut.IsDone())
return new App::DocumentObjectExecReturn("Section cut has failed");
TopoDS_Shape rawShape = mkCut.Shape();
Bnd_Box testBox;
BRepBndLib::Add(rawShape, testBox);
testBox.SetGap(0.0);
if (testBox.IsVoid()) { //prism & input don't intersect. rawShape is garbage, don't bother.
Base::Console().Log("INFO - DVS::execute - prism & input don't intersect\n");
return DrawView::execute();
}
gp_Pnt inputCenter;
try {
inputCenter = TechDrawGeometry::findCentroid(rawShape,
Direction.getValue());
TopoDS_Shape mirroredShape = TechDrawGeometry::mirrorShape(rawShape,
inputCenter,
Scale.getValue());
geometryObject = buildGeometryObject(mirroredShape,inputCenter); //this is original shape after cut by section prism
#if MOD_TECHDRAW_HANDLE_FACES
extractFaces();
#endif //#if MOD_TECHDRAW_HANDLE_FACES
}
catch (Standard_Failure) {
Handle_Standard_Failure e1 = Standard_Failure::Caught();
Base::Console().Log("LOG - DVS::execute - base shape failed for %s - %s **\n",getNameInDocument(),e1->GetMessageString());
return new App::DocumentObjectExecReturn(e1->GetMessageString());
}
try {
TopoDS_Compound sectionCompound = findSectionPlaneIntersections(rawShape);
TopoDS_Shape mirroredSection = TechDrawGeometry::mirrorShape(sectionCompound,
inputCenter,
Scale.getValue());
TopoDS_Compound newFaces;
BRep_Builder builder;
builder.MakeCompound(newFaces);
TopExp_Explorer expl(mirroredSection, TopAbs_FACE);
for (; expl.More(); expl.Next()) {
const TopoDS_Face& face = TopoDS::Face(expl.Current());
TopoDS_Face pFace = projectFace(face,
inputCenter,
Direction.getValue());
if (!pFace.IsNull()) {
builder.Add(newFaces,pFace);
}
}
//.........这里部分代码省略.........
示例10: process
bool FaceUniter::process()
{
if (workShell.IsNull())
return false;
modifiedShapes.clear();
deletedShapes.clear();
typeObjects.push_back(&getPlaneObject());
typeObjects.push_back(&getCylinderObject());
//add more face types.
ModelRefine::FaceTypeSplitter splitter;
splitter.addShell(workShell);
std::vector<FaceTypedBase *>::iterator typeIt;
for(typeIt = typeObjects.begin(); typeIt != typeObjects.end(); ++typeIt)
splitter.registerType((*typeIt)->getType());
splitter.split();
ModelRefine::FaceVectorType facesToRemove;
ModelRefine::FaceVectorType facesToSew;
ModelRefine::FaceAdjacencySplitter adjacencySplitter(workShell);
for(typeIt = typeObjects.begin(); typeIt != typeObjects.end(); ++typeIt)
{
ModelRefine::FaceVectorType typedFaces = splitter.getTypedFaceVector((*typeIt)->getType());
ModelRefine::FaceEqualitySplitter equalitySplitter;
equalitySplitter.split(typedFaces, *typeIt);
for (std::size_t indexEquality(0); indexEquality < equalitySplitter.getGroupCount(); ++indexEquality)
{
adjacencySplitter.split(equalitySplitter.getGroup(indexEquality));
// std::cout << " adjacency group count: " << adjacencySplitter.getGroupCount() << std::endl;
for (std::size_t adjacentIndex(0); adjacentIndex < adjacencySplitter.getGroupCount(); ++adjacentIndex)
{
// std::cout << " face count is: " << adjacencySplitter.getGroup(adjacentIndex).size() << std::endl;
TopoDS_Face newFace = (*typeIt)->buildFace(adjacencySplitter.getGroup(adjacentIndex));
if (!newFace.IsNull())
{
facesToSew.push_back(newFace);
if (facesToRemove.capacity() <= facesToRemove.size() + adjacencySplitter.getGroup(adjacentIndex).size())
facesToRemove.reserve(facesToRemove.size() + adjacencySplitter.getGroup(adjacentIndex).size());
FaceVectorType temp = adjacencySplitter.getGroup(adjacentIndex);
facesToRemove.insert(facesToRemove.end(), temp.begin(), temp.end());
// the first shape will be marked as modified, i.e. replaced by newFace, all others are marked as deleted
if (!temp.empty())
{
modifiedShapes.push_back(std::make_pair(temp.front(), newFace));
deletedShapes.insert(deletedShapes.end(), temp.begin()+1, temp.end());
}
}
}
}
}
if (facesToSew.size() > 0)
{
modifiedSignal = true;
workShell = ModelRefine::removeFaces(workShell, facesToRemove);
TopExp_Explorer xp;
bool emptyShell = true;
for (xp.Init(workShell, TopAbs_FACE); xp.More(); xp.Next())
{
emptyShell = false;
break;
}
if (!emptyShell || facesToSew.size() > 1)
{
BRepBuilderAPI_Sewing sew;
sew.Add(workShell);
FaceVectorType::iterator sewIt;
for(sewIt = facesToSew.begin(); sewIt != facesToSew.end(); ++sewIt)
sew.Add(*sewIt);
sew.Perform();
workShell = TopoDS::Shell(sew.SewedShape());
// update the list of modifications
for (std::vector<ShapePairType>::iterator it = modifiedShapes.begin(); it != modifiedShapes.end(); ++it)
{
if (sew.IsModified(it->second))
{
it->second = sew.Modified(it->second);
break;
}
}
}
else
{
// workShell has no more faces and we add exactly one face
BRep_Builder builder;
builder.MakeShell(workShell);
FaceVectorType::iterator sewIt;
for(sewIt = facesToSew.begin(); sewIt != facesToSew.end(); ++sewIt)
builder.Add(workShell, *sewIt);
}
BRepLib_FuseEdges edgeFuse(workShell, Standard_True);
TopTools_DataMapOfShapeShape affectedFaces;
edgeFuse.Faces(affectedFaces);
TopTools_DataMapIteratorOfDataMapOfShapeShape mapIt;
for (mapIt.Initialize(affectedFaces); mapIt.More(); mapIt.Next())
{
ShapeFix_Face faceFixer(TopoDS::Face(mapIt.Value()));
//.........这里部分代码省略.........
示例11: DocumentObjectExecReturn
App::DocumentObjectExecReturn *Pocket::execute(void)
{
// Handle legacy features, these typically have Type set to 3 (previously NULL, now UpToFace),
// empty FaceName (because it didn't exist) and a value for Length
if (std::string(Type.getValueAsString()) == "UpToFace" &&
(UpToFace.getValue() == NULL && Length.getValue() > Precision::Confusion()))
Type.setValue("Length");
// Validate parameters
double L = Length.getValue();
if ((std::string(Type.getValueAsString()) == "Length") && (L < Precision::Confusion()))
return new App::DocumentObjectExecReturn("Pocket: Length of pocket too small");
Part::Feature* obj = 0;
TopoDS_Face face;
try {
obj = getVerifiedObject();
face = getVerifiedFace();
} catch (const Base::Exception& e) {
return new App::DocumentObjectExecReturn(e.what());
}
// if the Base property has a valid shape, fuse the prism into it
TopoDS_Shape base;
try {
base = getBaseShape();
} catch (const Base::Exception&) {
return new App::DocumentObjectExecReturn("No sketch support and no base shape: Please tell me where to remove the material of the pocket!");
}
// get the Sketch plane
Base::Placement SketchPos = obj->Placement.getValue();
Base::Vector3d SketchVector = getProfileNormal();
// turn around for pockets
SketchVector *= -1;
try {
this->positionByPrevious();
TopLoc_Location invObjLoc = this->getLocation().Inverted();
base.Move(invObjLoc);
gp_Dir dir(SketchVector.x,SketchVector.y,SketchVector.z);
dir.Transform(invObjLoc.Transformation());
if (face.IsNull())
return new App::DocumentObjectExecReturn("Pocket: Creating a face from sketch failed");
face.Move(invObjLoc);
std::string method(Type.getValueAsString());
if (method == "UpToFirst" || method == "UpToFace") {
if (base.IsNull())
return new App::DocumentObjectExecReturn("Pocket: Extruding up to a face is only possible if the sketch is located on a face");
// Note: This will return an unlimited planar face if support is a datum plane
TopoDS_Face supportface = getSupportFace();
supportface.Move(invObjLoc);
if (Reversed.getValue())
dir.Reverse();
// Find a valid face or datum plane to extrude up to
TopoDS_Face upToFace;
if (method == "UpToFace") {
getUpToFaceFromLinkSub(upToFace, UpToFace);
upToFace.Move(invObjLoc);
}
getUpToFace(upToFace, base, supportface, face, method, dir, Offset.getValue());
// BRepFeat_MakePrism(..., 2, 1) in combination with PerForm(upToFace) is buggy when the
// prism that is being created is contained completely inside the base solid
// In this case the resulting shape is empty. This is not a problem for the Pad or Pocket itself
// but it leads to an invalid SubShape
// The bug only occurs when the upToFace is limited (by a wire), not for unlimited upToFace. But
// other problems occur with unlimited concave upToFace so it is not an option to always unlimit upToFace
// Check supportface for limits, otherwise Perform() throws an exception
TopExp_Explorer Ex(supportface,TopAbs_WIRE);
if (!Ex.More())
supportface = TopoDS_Face();
BRepFeat_MakePrism PrismMaker;
PrismMaker.Init(base, face, supportface, dir, 0, 1);
PrismMaker.Perform(upToFace);
if (!PrismMaker.IsDone())
return new App::DocumentObjectExecReturn("Pocket: Up to face: Could not extrude the sketch!");
TopoDS_Shape prism = PrismMaker.Shape();
// And the really expensive way to get the SubShape...
BRepAlgoAPI_Cut mkCut(base, prism);
if (!mkCut.IsDone())
return new App::DocumentObjectExecReturn("Pocket: Up to face: Could not get SubShape!");
// FIXME: In some cases this affects the Shape property: It is set to the same shape as the SubShape!!!!
TopoDS_Shape result = refineShapeIfActive(mkCut.Shape());
this->AddSubShape.setValue(result);
this->Shape.setValue(prism);
} else {
TopoDS_Shape prism;
generatePrism(prism, face, method, dir, L, 0.0,
Midplane.getValue(), Reversed.getValue());
//.........这里部分代码省略.........
示例12: DocumentObjectExecReturn
App::DocumentObjectExecReturn *Draft::execute(void)
{
// Get parameters
// Base shape
Part::TopoShape TopShape;
try {
TopShape = getBaseShape();
} catch (Base::Exception& e) {
return new App::DocumentObjectExecReturn(e.what());
}
// Faces where draft should be applied
// Note: Cannot be const reference currently because of BRepOffsetAPI_DraftAngle::Remove() bug, see below
std::vector<std::string> SubVals = Base.getSubValuesStartsWith("Face");
if (SubVals.size() == 0)
return new App::DocumentObjectExecReturn("No faces specified");
// Draft angle
double angle = Angle.getValue() / 180.0 * M_PI;
// Pull direction
gp_Dir pullDirection;
App::DocumentObject* refDirection = PullDirection.getValue();
if (refDirection != NULL) {
if (refDirection->getTypeId().isDerivedFrom(PartDesign::Line::getClassTypeId())) {
PartDesign::Line* line = static_cast<PartDesign::Line*>(refDirection);
Base::Vector3d d = line->getDirection();
pullDirection = gp_Dir(d.x, d.y, d.z);
} else if (refDirection->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
std::vector<std::string> subStrings = PullDirection.getSubValues();
if (subStrings.empty() || subStrings[0].empty())
throw Base::Exception("No pull direction reference specified");
Part::Feature* refFeature = static_cast<Part::Feature*>(refDirection);
Part::TopoShape refShape = refFeature->Shape.getShape();
TopoDS_Shape ref = refShape.getSubShape(subStrings[0].c_str());
if (ref.ShapeType() == TopAbs_EDGE) {
TopoDS_Edge refEdge = TopoDS::Edge(ref);
if (refEdge.IsNull())
throw Base::Exception("Failed to extract pull direction reference edge");
BRepAdaptor_Curve adapt(refEdge);
if (adapt.GetType() != GeomAbs_Line)
throw Base::Exception("Pull direction reference edge must be linear");
pullDirection = adapt.Line().Direction();
} else {
throw Base::Exception("Pull direction reference must be an edge or a datum line");
}
} else {
throw Base::Exception("Pull direction reference must be an edge of a feature or a datum line");
}
TopLoc_Location invObjLoc = this->getLocation().Inverted();
pullDirection.Transform(invObjLoc.Transformation());
}
// Neutral plane
gp_Pln neutralPlane;
App::DocumentObject* refPlane = NeutralPlane.getValue();
if (refPlane == NULL) {
// Try to guess a neutral plane from the first selected face
// Get edges of first selected face
TopoDS_Shape face = TopShape.getSubShape(SubVals[0].c_str());
TopTools_IndexedMapOfShape mapOfEdges;
TopExp::MapShapes(face, TopAbs_EDGE, mapOfEdges);
bool found = false;
for (int i = 1; i <= mapOfEdges.Extent(); i++) {
// Note: What happens if mapOfEdges(i) is the degenerated edge of a cone?
// But in that case the draft is not possible anyway!
BRepAdaptor_Curve c(TopoDS::Edge(mapOfEdges(i)));
gp_Pnt p1 = c.Value(c.FirstParameter());
gp_Pnt p2 = c.Value(c.LastParameter());
if (c.IsClosed()) {
// Edge is a circle or a circular arc (other types are not allowed for drafting)
neutralPlane = gp_Pln(p1, c.Circle().Axis().Direction());
found = true;
break;
} else {
// Edge is linear
// Find midpoint of edge and create auxiliary plane through midpoint normal to edge
gp_Pnt pm = c.Value((c.FirstParameter() + c.LastParameter()) / 2.0);
Handle(Geom_Plane) aux = new Geom_Plane(pm, gp_Dir(p2.X() - p1.X(), p2.Y() - p1.Y(), p2.Z() - p1.Z()));
// Intersect plane with face. Is there no easier way?
BRepAdaptor_Surface adapt(TopoDS::Face(face), Standard_False);
Handle(Geom_Surface) sf = adapt.Surface().Surface();
GeomAPI_IntSS intersector(aux, sf, Precision::Confusion());
if (!intersector.IsDone())
continue;
Handle(Geom_Curve) icurve = intersector.Line(1);
if (!icurve->IsKind(STANDARD_TYPE(Geom_Line)))
continue;
// TODO: How to extract the line from icurve without creating an edge first?
TopoDS_Edge edge = BRepBuilderAPI_MakeEdge(icurve);
BRepAdaptor_Curve c(edge);
neutralPlane = gp_Pln(pm, c.Line().Direction());
found = true;
break;
//.........这里部分代码省略.........
示例13: process
bool FaceUniter::process()
{
if (workShell.IsNull())
return false;
modifiedShapes.clear();
deletedShapes.clear();
typeObjects.push_back(&getPlaneObject());
typeObjects.push_back(&getCylinderObject());
//add more face types.
ModelRefine::FaceTypeSplitter splitter;
splitter.addShell(workShell);
std::vector<FaceTypedBase *>::iterator typeIt;
for(typeIt = typeObjects.begin(); typeIt != typeObjects.end(); ++typeIt)
splitter.registerType((*typeIt)->getType());
splitter.split();
ModelRefine::FaceVectorType facesToRemove;
ModelRefine::FaceVectorType facesToSew;
ModelRefine::FaceAdjacencySplitter adjacencySplitter(workShell);
for(typeIt = typeObjects.begin(); typeIt != typeObjects.end(); ++typeIt)
{
ModelRefine::FaceVectorType typedFaces = splitter.getTypedFaceVector((*typeIt)->getType());
ModelRefine::FaceEqualitySplitter equalitySplitter;
equalitySplitter.split(typedFaces, *typeIt);
for (std::size_t indexEquality(0); indexEquality < equalitySplitter.getGroupCount(); ++indexEquality)
{
adjacencySplitter.split(equalitySplitter.getGroup(indexEquality));
// std::cout << " adjacency group count: " << adjacencySplitter.getGroupCount() << std::endl;
for (std::size_t adjacentIndex(0); adjacentIndex < adjacencySplitter.getGroupCount(); ++adjacentIndex)
{
// std::cout << " face count is: " << adjacencySplitter.getGroup(adjacentIndex).size() << std::endl;
TopoDS_Face newFace = (*typeIt)->buildFace(adjacencySplitter.getGroup(adjacentIndex));
if (!newFace.IsNull())
{
facesToSew.push_back(newFace);
if (facesToRemove.capacity() <= facesToRemove.size() + adjacencySplitter.getGroup(adjacentIndex).size())
facesToRemove.reserve(facesToRemove.size() + adjacencySplitter.getGroup(adjacentIndex).size());
FaceVectorType temp = adjacencySplitter.getGroup(adjacentIndex);
facesToRemove.insert(facesToRemove.end(), temp.begin(), temp.end());
// the first shape will be marked as modified, i.e. replaced by newFace, all others are marked as deleted
// jrheinlaender: IMHO this is not correct because references to the deleted faces will be broken, whereas they should
// be replaced by references to the new face. To achieve this all shapes should be marked as
// modified, producing one single new face. This is the inverse behaviour to faces that are split e.g.
// by a boolean cut, where one old shape is marked as modified, producing multiple new shapes
if (!temp.empty())
{
for (FaceVectorType::iterator f = temp.begin(); f != temp.end(); ++f)
modifiedShapes.push_back(std::make_pair(*f, newFace));
}
}
}
}
}
if (facesToSew.size() > 0)
{
modifiedSignal = true;
workShell = ModelRefine::removeFaces(workShell, facesToRemove);
TopExp_Explorer xp;
bool emptyShell = true;
for (xp.Init(workShell, TopAbs_FACE); xp.More(); xp.Next())
{
emptyShell = false;
break;
}
if (!emptyShell || facesToSew.size() > 1)
{
BRepBuilderAPI_Sewing sew;
sew.Add(workShell);
FaceVectorType::iterator sewIt;
for(sewIt = facesToSew.begin(); sewIt != facesToSew.end(); ++sewIt)
sew.Add(*sewIt);
sew.Perform();
try {
workShell = TopoDS::Shell(sew.SewedShape());
} catch (Standard_Failure) {
return false;
}
// update the list of modifications
for (std::vector<ShapePairType>::iterator it = modifiedShapes.begin(); it != modifiedShapes.end(); ++it)
{
if (sew.IsModified(it->second))
{
it->second = sew.Modified(it->second);
break;
}
}
}
else
{
// workShell has no more faces and we add exactly one face
BRep_Builder builder;
builder.MakeShell(workShell);
FaceVectorType::iterator sewIt;
for(sewIt = facesToSew.begin(); sewIt != facesToSew.end(); ++sewIt)
builder.Add(workShell, *sewIt);
}
//.........这里部分代码省略.........
示例14: BuildShapeMesh
void BuildShapeMesh(osg::Geode *geode, const TopoDS_Shape &shape, const osg::Vec4 &color, double deflection)
{
bool bSetNormal = true;
osg::ref_ptr<deprecated_osg::Geometry> triGeom = new deprecated_osg::Geometry();
osg::ref_ptr<osg::Vec3Array> theVertices = new osg::Vec3Array();
osg::ref_ptr<osg::Vec3Array> theNormals = new osg::Vec3Array();
BRepMesh::Mesh(shape, deflection);
TopExp_Explorer faceExplorer;
for (faceExplorer.Init(shape, TopAbs_FACE); faceExplorer.More(); faceExplorer.Next())
{
TopLoc_Location theLocation;
TopoDS_Face theFace = TopoDS::Face(faceExplorer.Current());
if (theFace.IsNull())
continue;
const Handle_Poly_Triangulation &theTriangulation = BRep_Tool::Triangulation(theFace, theLocation);
BRepLProp_SLProps theProp(BRepAdaptor_Surface(theFace), 1, Precision::Confusion());
Standard_Integer nTriangles = theTriangulation->NbTriangles();
for (Standard_Integer i = 1; i <= nTriangles; i++)
{
const Poly_Triangle& theTriangle = theTriangulation->Triangles().Value(i);
gp_Pnt theVertex1 = theTriangulation->Nodes().Value(theTriangle(1));
gp_Pnt theVertex2 = theTriangulation->Nodes().Value(theTriangle(2));
gp_Pnt theVertex3 = theTriangulation->Nodes().Value(theTriangle(3));
const gp_Pnt2d &theUV1 = theTriangulation->UVNodes().Value(theTriangle(1));
const gp_Pnt2d &theUV2 = theTriangulation->UVNodes().Value(theTriangle(2));
const gp_Pnt2d &theUV3 = theTriangulation->UVNodes().Value(theTriangle(3));
theVertex1.Transform(theLocation.Transformation());
theVertex2.Transform(theLocation.Transformation());
theVertex3.Transform(theLocation.Transformation());
// find the normal for the triangle mesh.
gp_Vec V12(theVertex1, theVertex2);
gp_Vec V13(theVertex1, theVertex3);
gp_Vec theNormal = V12 ^ V13;
gp_Vec theNormal1 = theNormal;
gp_Vec theNormal2 = theNormal;
gp_Vec theNormal3 = theNormal;
if (theNormal.Magnitude() > Precision::Confusion())
{
theNormal.Normalize();
theNormal1.Normalize();
theNormal2.Normalize();
theNormal3.Normalize();
}
theProp.SetParameters(theUV1.X(), theUV1.Y());
if (theProp.IsNormalDefined())
{
theNormal1 = theProp.Normal();
}
theProp.SetParameters(theUV2.X(), theUV2.Y());
if (theProp.IsNormalDefined())
{
theNormal2 = theProp.Normal();
}
theProp.SetParameters(theUV3.X(), theUV3.Y());
if (theProp.IsNormalDefined())
{
theNormal3 = theProp.Normal();
}
if (theFace.Orientation() == TopAbs_REVERSED)
{
theNormal.Reverse();
theNormal1.Reverse();
theNormal2.Reverse();
theNormal3.Reverse();
}
theVertices->push_back(osg::Vec3(theVertex1.X(), theVertex1.Y(), theVertex1.Z()));
theVertices->push_back(osg::Vec3(theVertex2.X(), theVertex2.Y(), theVertex2.Z()));
theVertices->push_back(osg::Vec3(theVertex3.X(), theVertex3.Y(), theVertex3.Z()));
if (bSetNormal)
{
theNormals->push_back(osg::Vec3(theNormal1.X(), theNormal1.Y(), theNormal1.Z()));
theNormals->push_back(osg::Vec3(theNormal2.X(), theNormal2.Y(), theNormal2.Z()));
theNormals->push_back(osg::Vec3(theNormal3.X(), theNormal3.Y(), theNormal3.Z()));
}
else
{
theNormals->push_back(osg::Vec3(theNormal.X(), theNormal.Y(), theNormal.Z()));
theNormals->push_back(osg::Vec3(theNormal.X(), theNormal.Y(), theNormal.Z()));
theNormals->push_back(osg::Vec3(theNormal.X(), theNormal.Y(), theNormal.Z()));
}
}
}
triGeom->setVertexArray(theVertices.get());
//.........这里部分代码省略.........
示例15: Exception
const std::list<gp_Trsf> LinearPattern::getTransformations(const std::vector<App::DocumentObject*>)
{
double distance = Length.getValue();
if (distance < Precision::Confusion())
throw Base::Exception("Pattern length too small");
int occurrences = Occurrences.getValue();
if (occurrences < 2)
throw Base::Exception("At least two occurrences required");
bool reversed = Reversed.getValue();
double offset = distance / (occurrences - 1);
App::DocumentObject* refObject = Direction.getValue();
if (refObject == NULL)
throw Base::Exception("No direction reference specified");
std::vector<std::string> subStrings = Direction.getSubValues();
if (subStrings.empty())
throw Base::Exception("No direction reference specified");
gp_Dir dir;
if (refObject->getTypeId().isDerivedFrom(Part::Part2DObject::getClassTypeId())) {
Part::Part2DObject* refSketch = static_cast<Part::Part2DObject*>(refObject);
Base::Axis axis;
if (subStrings[0] == "H_Axis")
axis = refSketch->getAxis(Part::Part2DObject::H_Axis);
else if (subStrings[0] == "V_Axis")
axis = refSketch->getAxis(Part::Part2DObject::V_Axis);
else if (subStrings[0] == "N_Axis")
axis = refSketch->getAxis(Part::Part2DObject::N_Axis);
else if (subStrings[0].size() > 4 && subStrings[0].substr(0,4) == "Axis") {
int AxId = std::atoi(subStrings[0].substr(4,4000).c_str());
if (AxId >= 0 && AxId < refSketch->getAxisCount())
axis = refSketch->getAxis(AxId);
}
axis *= refSketch->Placement.getValue();
dir = gp_Dir(axis.getDirection().x, axis.getDirection().y, axis.getDirection().z);
} else if (refObject->getTypeId().isDerivedFrom(PartDesign::Plane::getClassTypeId())) {
PartDesign::Plane* plane = static_cast<PartDesign::Plane*>(refObject);
Base::Vector3d d = plane->getNormal();
dir = gp_Dir(d.x, d.y, d.z);
} else if (refObject->getTypeId().isDerivedFrom(PartDesign::Line::getClassTypeId())) {
PartDesign::Line* line = static_cast<PartDesign::Line*>(refObject);
Base::Vector3d d = line->getDirection();
dir = gp_Dir(d.x, d.y, d.z);
} else if (refObject->getTypeId().isDerivedFrom(App::Line::getClassTypeId())) {
App::Line* line = static_cast<App::Line*>(refObject);
Base::Rotation rot = line->Placement.getValue().getRotation();
Base::Vector3d d(1,0,0);
rot.multVec(d, d);
dir = gp_Dir(d.x, d.y, d.z);
} else if (refObject->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())) {
if (subStrings[0].empty())
throw Base::Exception("No direction reference specified");
Part::Feature* refFeature = static_cast<Part::Feature*>(refObject);
Part::TopoShape refShape = refFeature->Shape.getShape();
TopoDS_Shape ref = refShape.getSubShape(subStrings[0].c_str());
if (ref.ShapeType() == TopAbs_FACE) {
TopoDS_Face refFace = TopoDS::Face(ref);
if (refFace.IsNull())
throw Base::Exception("Failed to extract direction plane");
BRepAdaptor_Surface adapt(refFace);
if (adapt.GetType() != GeomAbs_Plane)
throw Base::Exception("Direction face must be planar");
dir = adapt.Plane().Axis().Direction();
} else if (ref.ShapeType() == TopAbs_EDGE) {
TopoDS_Edge refEdge = TopoDS::Edge(ref);
if (refEdge.IsNull())
throw Base::Exception("Failed to extract direction edge");
BRepAdaptor_Curve adapt(refEdge);
if (adapt.GetType() != GeomAbs_Line)
throw Base::Exception("Direction edge must be a straight line");
dir = adapt.Line().Direction();
} else {
throw Base::Exception("Direction reference must be edge or face");
}
} else {
throw Base::Exception("Direction reference must be edge/face of a feature or a datum line/plane");
}
TopLoc_Location invObjLoc = this->getLocation().Inverted();
dir.Transform(invObjLoc.Transformation());
gp_Vec direction(dir.X(), dir.Y(), dir.Z());
if (reversed)
direction.Reverse();
// Note: The original feature is NOT included in the list of transformations! Therefore
// we start with occurrence number 1, not number 0
std::list<gp_Trsf> transformations;
gp_Trsf trans;
transformations.push_back(trans); // identity transformation
for (int i = 1; i < occurrences; i++) {
trans.SetTranslation(direction * i * offset);
transformations.push_back(trans);
}
//.........这里部分代码省略.........