本文整理汇总了C++中TopoDS_Shape::IsNull方法的典型用法代码示例。如果您正苦于以下问题:C++ TopoDS_Shape::IsNull方法的具体用法?C++ TopoDS_Shape::IsNull怎么用?C++ TopoDS_Shape::IsNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TopoDS_Shape
的用法示例。
在下文中一共展示了TopoDS_Shape::IsNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Exception
std::vector<TopoDS_Wire> SketchBased::getSketchWires() const {
std::vector<TopoDS_Wire> result;
TopoDS_Shape shape = getVerifiedSketch()->Shape.getShape()._Shape;
if (shape.IsNull())
throw Base::Exception("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 almost happens when re-computing the shape but sometimes also for the
// first time
BRepBuilderAPI_Copy copy(shape);
shape = copy.Shape();
if (shape.IsNull())
throw Base::Exception("Linked shape object is empty");
TopExp_Explorer ex;
for (ex.Init(shape, TopAbs_WIRE); ex.More(); ex.Next()) {
result.push_back(TopoDS::Wire(ex.Current()));
}
if (result.empty()) // there can be several wires
throw Base::Exception("Linked shape object is not a wire");
return result;
}
示例2: Execute
//=======================================================================
//function : Execute
//purpose :
//=======================================================================
Standard_Integer GEOMImpl_CylinderDriver::Execute(TFunction_Logbook& log) const
{
if (Label().IsNull()) return 0;
Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
GEOMImpl_ICylinder aCI (aFunction);
Standard_Integer aType = aFunction->GetType();
gp_Pnt aP;
gp_Vec aV;
if (aType == CYLINDER_R_H) {
aP = gp::Origin();
aV = gp::DZ();
}
else if (aType == CYLINDER_PNT_VEC_R_H) {
Handle(GEOM_Function) aRefPoint = aCI.GetPoint();
Handle(GEOM_Function) aRefVector = aCI.GetVector();
TopoDS_Shape aShapePnt = aRefPoint->GetValue();
TopoDS_Shape aShapeVec = aRefVector->GetValue();
if (aShapePnt.IsNull() || aShapeVec.IsNull()) {
Standard_NullObject::Raise("Cylinder creation aborted: point or vector is not defined");
}
if (aShapePnt.ShapeType() != TopAbs_VERTEX ||
aShapeVec.ShapeType() != TopAbs_EDGE) {
Standard_TypeMismatch::Raise("Cylinder creation aborted: point or vector shapes has wrong type");
}
aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
TopoDS_Vertex V1, V2;
TopExp::Vertices(anE, V1, V2, Standard_True);
if (V1.IsNull() || V2.IsNull()) {
Standard_NullObject::Raise("Cylinder creation aborted: vector is not defined");
}
aV = gp_Vec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
}
else {
return 0;
}
if (aCI.GetH() < 0.0) aV.Reverse();
gp_Ax2 anAxes (aP, aV);
BRepPrimAPI_MakeCylinder MC (anAxes, aCI.GetR(), Abs(aCI.GetH()));
MC.Build();
if (!MC.IsDone()) {
StdFail_NotDone::Raise("Cylinder can't be computed from the given parameters");
}
TopoDS_Shape aShape = MC.Shape();
if (aShape.IsNull()) return 0;
aFunction->SetValue(aShape);
log.SetTouched(Label());
return 1;
}
示例3: Execute
//=======================================================================
//function : Execute
//purpose :
//=======================================================================
Standard_Integer GEOM_SubShapeDriver::Execute(TFunction_Logbook& log) const
{
if (Label().IsNull()) return 0;
Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
GEOM_ISubShape aCI (aFunction);
TDF_Label aLabel = aCI.GetMainShape()->GetOwnerEntry();
if (aLabel.IsRoot()) return 0;
Handle(GEOM_Object) anObj = GEOM_Object::GetObject(aLabel);
if (anObj.IsNull()) return 0;
TopoDS_Shape aMainShape = anObj->GetValue();
if (aMainShape.IsNull()) return 0;
Handle(TColStd_HArray1OfInteger) anIndices = aCI.GetIndices();
if (anIndices.IsNull() || anIndices->Length() <= 0) return 0;
BRep_Builder B;
TopoDS_Compound aCompound;
TopoDS_Shape aShape;
if (anIndices->Length() == 1 && anIndices->Value(1) == -1) { //The empty sub-shape
B.MakeCompound(aCompound);
aShape = aCompound;
}
else {
TopTools_IndexedMapOfShape aMapOfShapes;
TopExp::MapShapes(aMainShape, aMapOfShapes);
if (anIndices->Length() > 1) {
B.MakeCompound(aCompound);
for (int i = anIndices->Lower(); i <= anIndices->Upper(); i++) {
if (aMapOfShapes.Extent() < anIndices->Value(i))
Standard_NullObject::Raise("GEOM_SubShapeDriver::Execute: Index is out of range");
TopoDS_Shape aSubShape = aMapOfShapes.FindKey(anIndices->Value(i));
if (aSubShape.IsNull()) continue;
B.Add(aCompound,aSubShape);
}
aShape = aCompound;
}
else {
int i = anIndices->Lower();
if (aMapOfShapes.Extent() < anIndices->Value(i))
Standard_NullObject::Raise("GEOM_SubShapeDriver::Execute: Index is out of range");
aShape = aMapOfShapes.FindKey(anIndices->Value(i));
}
}
if (aShape.IsNull()) return 0;
aFunction->SetValue(aShape);
log.SetTouched(Label());
return 1;
}
示例4: isReplace
Standard_Boolean ShHealOper_RemoveFace::isReplace(const TopoDS_Shape& theShape,
TopoDS_Shape& theNewShape)
{
Standard_Boolean isChange = Standard_False;
TopTools_SequenceOfShape aSeqShapes;
if(theShape.ShapeType() == TopAbs_COMPOUND || theShape.ShapeType() == TopAbs_COMPSOLID ||
theShape.ShapeType() == TopAbs_SOLID) {
TopoDS_Iterator aEs(theShape);
for( ; aEs.More(); aEs.Next()) {
TopoDS_Shape aNewShell = aEs.Value();
if(aNewShell.ShapeType()!= TopAbs_SHELL) {
aSeqShapes.Append(aNewShell);
continue;
}
TopoDS_Shape as = getResultShell(TopoDS::Shell(aNewShell));
isChange = (as.IsNull() || (as.ShapeType() == TopAbs_FACE));
if(!as.IsNull()) {
aSeqShapes.Append(as);
}
}
}
else if(theShape.ShapeType() == TopAbs_SHELL) {
TopoDS_Shape aSh = getResultShell(TopoDS::Shell(theShape));
isChange = (aSh.IsNull() || (aSh.ShapeType() == TopAbs_FACE));
if(!aSh.IsNull())
aSeqShapes.Append(aSh);
}
else aSeqShapes.Append(theShape);
if(aSeqShapes.IsEmpty())
return Standard_True;
if(isChange) {
if(aSeqShapes.Length() == 1)
theNewShape = aSeqShapes.Value(1);
else if (aSeqShapes.Length() > 1) {
TopoDS_Compound aComp1;
BRep_Builder aBB;
aBB.MakeCompound(aComp1);
Standard_Integer kk =1;
for( ; kk <= aSeqShapes.Length(); kk++)
aBB.Add(aComp1,aSeqShapes.Value(kk));
if(aSeqShapes.Length())
theNewShape = aComp1;
}
}
else
theNewShape = theShape;
return isChange;
}
示例5: 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();
}
示例6: findSectionPlaneIntersections
//! tries to find the intersection of the section plane with the shape giving a collection of planar faces
TopoDS_Compound DrawViewSection::findSectionPlaneIntersections(const TopoDS_Shape& shape)
{
TopoDS_Compound result;
if(shape.IsNull()){
Base::Console().Log("DrawViewSection::getSectionSurface - Sectional View shape is Empty\n");
return result;
}
gp_Pln plnSection = getSectionPlane();
BRep_Builder builder;
builder.MakeCompound(result);
TopExp_Explorer expFaces(shape, TopAbs_FACE);
int i;
int dbAdded = 0;
for (i = 1 ; expFaces.More(); expFaces.Next(), i++) {
const TopoDS_Face& face = TopoDS::Face(expFaces.Current());
BRepAdaptor_Surface adapt(face);
if (adapt.GetType() == GeomAbs_Plane){
gp_Pln plnFace = adapt.Plane();
if(plnSection.Contains(plnFace.Location(), Precision::Confusion()) &&
plnFace.Axis().IsParallel(plnSection.Axis(), Precision::Angular())) {
dbAdded++;
builder.Add(result, face);
}
}
}
return result;
}
示例7: allow
bool allow(App::Document*pDoc, App::DocumentObject*pObj, const char*sSubName)
{
this->canSelect = false;
if (!pObj->isDerivedFrom(Part::Feature::getClassTypeId()))
return false;
if (!sSubName || sSubName[0] == '\0')
return false;
std::string element(sSubName);
if (element.substr(0,4) != "Edge")
return false;
Part::Feature* fea = static_cast<Part::Feature*>(pObj);
try {
TopoDS_Shape sub = fea->Shape.getShape().getSubShape(sSubName);
if (!sub.IsNull() && sub.ShapeType() == TopAbs_EDGE) {
const TopoDS_Edge& edge = TopoDS::Edge(sub);
BRepAdaptor_Curve adapt(edge);
if (adapt.GetType() == GeomAbs_Line) {
gp_Lin line = adapt.Line();
this->loc = line.Location();
this->dir = line.Direction();
this->canSelect = true;
return true;
}
}
}
catch (...) {
}
return false;
}
示例8: DocumentObjectExecReturn
App::DocumentObjectExecReturn *Revolution::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 *base = static_cast<Part::Feature*>(Source.getValue());
Base::Vector3d b = Base.getValue();
Base::Vector3d v = Axis.getValue();
gp_Pnt pnt(b.x,b.y,b.z);
gp_Dir dir(v.x,v.y,v.z);
Standard_Boolean isSolid = Solid.getValue() ? Standard_True : Standard_False;
try {
// Now, let's get the TopoDS_Shape
//TopoDS_Shape revolve = base->Shape.getShape().revolve(gp_Ax1(pnt, dir),
// Angle.getValue()/180.0f*M_PI);
TopoDS_Shape revolve = base->Shape.getShape().revolve(gp_Ax1(pnt, dir),
Angle.getValue()/180.0f*M_PI,isSolid);
if (revolve.IsNull())
return new App::DocumentObjectExecReturn("Resulting shape is null");
this->Shape.setValue(revolve);
return App::DocumentObject::StdReturn;
}
catch (Standard_Failure) {
Handle_Standard_Failure e = Standard_Failure::Caught();
return new App::DocumentObjectExecReturn(e->GetMessageString());
}
}
示例9: autoSolid
void DlgExtrusion::autoSolid()
{
try{
App::DocumentObject &dobj = this->getShapeToExtrude();
if (dobj.isDerivedFrom(Part::Feature::getClassTypeId())){
Part::Feature &feature = static_cast<Part::Feature&>(dobj);
TopoDS_Shape sh = feature.Shape.getValue();
if (sh.IsNull())
return;
ShapeExtend_Explorer xp;
Handle(TopTools_HSequenceOfShape) leaves = xp.SeqFromCompound(sh, /*recursive= */Standard_True);
int cntClosedWires = 0;
for(int i = 0; i < leaves->Length(); i++){
const TopoDS_Shape &leaf = leaves->Value(i+1);
if (leaf.IsNull())
return;
if (leaf.ShapeType() == TopAbs_WIRE || leaf.ShapeType() == TopAbs_EDGE){
if (BRep_Tool::IsClosed(leaf)){
cntClosedWires++;
}
}
}
ui->chkSolid->setChecked( cntClosedWires == leaves->Length() );
}
} catch(...) {
}
}
示例10: isPathValid
bool SweepWidget::isPathValid(const Gui::SelectionObject& sel) const
{
const App::DocumentObject* path = sel.getObject();
if (!(path && path->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId())))
return false;
const std::vector<std::string>& sub = sel.getSubNames();
TopoDS_Shape pathShape;
const Part::TopoShape& shape = static_cast<const Part::Feature*>(path)->Shape.getValue();
if (!sub.empty()) {
try {
BRepBuilderAPI_MakeWire mkWire;
for (std::vector<std::string>::const_iterator it = sub.begin(); it != sub.end(); ++it) {
TopoDS_Shape subshape = shape.getSubShape(it->c_str());
mkWire.Add(TopoDS::Edge(subshape));
}
pathShape = mkWire.Wire();
}
catch (...) {
return false;
}
}
else if (shape._Shape.ShapeType() == TopAbs_EDGE) {
pathShape = shape._Shape;
}
else if (shape._Shape.ShapeType() == TopAbs_WIRE) {
BRepBuilderAPI_MakeWire mkWire(TopoDS::Wire(shape._Shape));
pathShape = mkWire.Wire();
}
return (!pathShape.IsNull());
}
示例11:
bool IfcGeom::Kernel::convert(const IfcSchema::IfcCompositeProfileDef* l, TopoDS_Shape& face) {
// BRepBuilderAPI_MakeFace mf;
TopoDS_Compound compound;
BRep_Builder builder;
builder.MakeCompound(compound);
IfcSchema::IfcProfileDef::list::ptr profiles = l->Profiles();
//bool first = true;
for (IfcSchema::IfcProfileDef::list::it it = profiles->begin(); it != profiles->end(); ++it) {
TopoDS_Face f;
if (convert_face(*it, f)) {
builder.Add(compound, f);
/* TopExp_Explorer exp(f, TopAbs_WIRE);
for (; exp.More(); exp.Next()) {
const TopoDS_Wire& wire = TopoDS::Wire(exp.Current());
if (first) {
mf.Init(BRepBuilderAPI_MakeFace(wire));
} else {
mf.Add(wire);
}
first = false;
} */
}
}
face = compound;
return !face.IsNull();
}
示例12: Perform
/**
* @todo: it would be nice if this algorithm would support
* some progress bar interface
*/
void CTiglFusePlane::Perform()
{
if (_hasPerformed) {
return;
}
CTiglUIDManager& uidManager = _myconfig.GetUIDManager();
CTiglAbstractPhysicalComponent* rootComponent = uidManager.GetRootComponent();
if (!rootComponent) {
LOG(ERROR) << "Root component of plane not found. Cannot create fused plane.";
return;
}
_result = FuseWithChilds(rootComponent);
CCPACSFarField& farfield = _myconfig.GetFarField();
if (farfield.GetFieldType() != NONE && (_mymode == FULL_PLANE_TRIMMED_FF || _mymode == HALF_PLANE_TRIMMED_FF)) {
PNamedShape ff = farfield.GetLoft();
BOPCol_ListOfShape aLS;
aLS.Append(_result->Shape());
aLS.Append(ff->Shape());
BOPAlgo_PaveFiller dsfill;
dsfill.SetArguments(aLS);
dsfill.Perform();
CTrimShape trim1(_result, ff, dsfill, INCLUDE);
PNamedShape resulttrimmed = trim1.NamedShape();
CTrimShape trim2(ff, _result, dsfill, EXCLUDE);
_farfield = trim2.NamedShape();
_result = resulttrimmed;
// trim intersections with far field
ListPNamedShape::iterator intIt = _intersections.begin();
ListPNamedShape newInts;
for (; intIt != _intersections.end(); ++intIt) {
PNamedShape inters = *intIt;
if (!inters) {
continue;
}
TopoDS_Shape sh = inters->Shape();
sh = BRepAlgoAPI_Common(sh, ff->Shape());
if (! sh.IsNull()) {
inters->SetShape(sh);
newInts.push_back(inters);
}
}
_intersections = newInts;
}
if (_result) {
_result->SetName(_myconfig.GetUID().c_str());
_result->SetShortName("AIRCRAFT");
}
_hasPerformed = true;
}
示例13: 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;
}
示例14: curveOnSurface
PyObject* TopoShapeFacePy::curveOnSurface(PyObject *args)
{
PyObject* e;
if (!PyArg_ParseTuple(args, "O!", &(TopoShapeEdgePy::Type), &e))
return 0;
try {
TopoDS_Shape shape = static_cast<TopoShapeEdgePy*>(e)->getTopoShapePtr()->getShape();
if (shape.IsNull()) {
PyErr_SetString(PyExc_RuntimeError, "invalid shape");
return 0;
}
TopoDS_Edge edge = TopoDS::Edge(shape);
const TopoDS_Face& face = TopoDS::Face(getTopoShapePtr()->getShape());
Standard_Real first, last;
Handle(Geom2d_Curve) curve = BRep_Tool::CurveOnSurface(edge, face, first, last);
std::unique_ptr<Part::Geom2dCurve> geo2d = getCurve2dFromGeom2d(curve);
if (!geo2d)
Py_Return;
Py::Tuple tuple(3);
tuple.setItem(0, Py::asObject(geo2d->getPyObject()));
tuple.setItem(1, Py::Float(first));
tuple.setItem(2, Py::Float(last));
return Py::new_reference_to(tuple);
}
catch (Standard_Failure& e) {
PyErr_SetString(PartExceptionOCCError, e.GetMessageString());
return 0;
}
}
示例15: importVRML
bool Translator::importVRML(const QString& file)
{
VrmlData_Scene vrmlScene;
filebuf fb;
fb.open(file.toUtf8().data(), ios::in);
if(fb.is_open() == false)
return false;
Standard_IStream input(&fb);
vrmlScene << input;
fb.close();
if(vrmlScene.Status() != VrmlData_StatusOK)
return false;
VrmlData_DataMapOfShapeAppearance map;
TopoDS_Shape shape = vrmlScene.GetShape(map);
if(shape.IsNull()) return false;
m_doc->insert(shape, QFileInfo(file).baseName());
return true;
}