void occQt::testCut() { gp_Ax2 anAxis; anAxis.SetLocation(gp_Pnt(0.0, 90.0, 0.0)); TopoDS_Shape aTopoBox = BRepPrimAPI_MakeBox(anAxis, 3.0, 4.0, 5.0); TopoDS_Shape aTopoSphere = BRepPrimAPI_MakeSphere(anAxis, 2.5); TopoDS_Shape aCuttedShape1 = BRepAlgoAPI_Cut(aTopoBox, aTopoSphere); TopoDS_Shape aCuttedShape2 = BRepAlgoAPI_Cut(aTopoSphere, aTopoBox); gp_Trsf aTrsf; aTrsf.SetTranslation(gp_Vec(8.0, 0.0, 0.0)); BRepBuilderAPI_Transform aTransform1(aCuttedShape1, aTrsf); aTrsf.SetTranslation(gp_Vec(16.0, 0.0, 0.0)); BRepBuilderAPI_Transform aTransform2(aCuttedShape2, aTrsf); Handle_AIS_Shape anAisBox = new AIS_Shape(aTopoBox); Handle_AIS_Shape anAisSphere = new AIS_Shape(aTopoSphere); Handle_AIS_Shape anAisCuttedShape1 = new AIS_Shape(aTransform1.Shape()); Handle_AIS_Shape anAisCuttedShape2 = new AIS_Shape(aTransform2.Shape()); anAisBox->SetColor(Quantity_NOC_SPRINGGREEN); anAisSphere->SetColor(Quantity_NOC_STEELBLUE); anAisCuttedShape1->SetColor(Quantity_NOC_TAN); anAisCuttedShape2->SetColor(Quantity_NOC_SALMON); mContext->Display(anAisBox); mContext->Display(anAisSphere); mContext->Display(anAisCuttedShape1); mContext->Display(anAisCuttedShape2); }
void Werkstuck::LHY(float endPunkt, float Rwz, float Hwz) //гориз. прямое фрезерование по оси Z // endPunkt - конечная точка { if (Zwz<(H0+Rwz)) { gp_Pnt punkt_zent(Xwz,Ywz,Zwz); gp_Dir wzNormal = gp::DY(); gp_Ax2 wzAchse(punkt_zent,wzNormal); BRepPrimAPI_MakeCylinder zLHY(wzAchse,Rwz,endPunkt-Ywz); TopoDS_Shape sLHY=zLHY.Shape(); WS = BRepAlgoAPI_Cut(WS,sLHY); } Ywz=endPunkt; }
TopoDS_Shape BRLFile::PerformBoolean(union tree *tp) { TopoDS_Shape left, right, result; if(tp->tr_op==OP_UNION || tp->tr_op==OP_INTERSECT || tp->tr_op==OP_SUBTRACT ) { left=PerformBoolean(tp->tr_b.tb_left); right=PerformBoolean(tp->tr_b.tb_right); } if(verbose&BRL) { switch(tp->tr_op) { case OP_UNION: case OP_INTERSECT: case OP_SUBTRACT: cout<< " Bool " << *tp; break; case OP_DB_LEAF: if(verbose&BRL) cout << " Leaf " << tp->tr_l.tl_name; break; } cout << " remaining " << construction.size() << '\n'; } switch(tp->tr_op) { case OP_UNION: return BRepAlgoAPI_Fuse(left,right); case OP_INTERSECT:return BRepAlgoAPI_Common(left,right); case OP_SUBTRACT: return BRepAlgoAPI_Cut(left,right); case OP_DB_LEAF: result=construction.back(); construction.pop_back(); return result; default: std::cerr << "Invalid boolean operation in " << __FUNCTION__ << '\n'; return result; } }
static bool Cut(const std::list<TopoDS_Shape> &shapes, TopoDS_Shape& new_shape){ if(shapes.size() < 2)return false; try { std::list<TopoDS_Shape>::const_iterator It = shapes.begin(); TopoDS_Shape current_shape = *It; It++; while(It != shapes.end()) { const TopoDS_Shape &cutting_shape = *It; current_shape = BRepAlgoAPI_Cut(current_shape, cutting_shape); It++; } new_shape = current_shape; return true; } catch (Standard_Failure) { Handle_Standard_Failure e = Standard_Failure::Caught(); wxMessageBox(wxString(_("Error with cut operation")) + _T(": ") + Ctt(e->GetMessageString())); return false; } }
// create the PCB (board only) model using the current outlines and drill holes bool PCBMODEL::CreatePCB() { if( m_hasPCB ) { if( m_pcb_label.IsNull() ) return false; return true; } if( m_curves.empty() || m_mincurve == m_curves.end() ) { m_hasPCB = true; std::ostringstream ostr; ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; ostr << " * no valid board outline\n"; wxLogMessage( "%s\n", ostr.str().c_str() ); return false; } m_hasPCB = true; // whether or not operations fail we note that CreatePCB has been invoked TopoDS_Shape board; OUTLINE oln; // loop to assemble (represents PCB outline and cutouts) oln.AddSegment( *m_mincurve ); m_curves.erase( m_mincurve ); while( !m_curves.empty() ) { if( oln.IsClosed() ) { if( board.IsNull() ) { if( !oln.MakeShape( board, m_thickness ) ) { std::ostringstream ostr; ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; ostr << " * could not create board extrusion\n"; wxLogMessage( "%s\n", ostr.str().c_str() ); return false; } } else { TopoDS_Shape hole; if( oln.MakeShape( hole, m_thickness ) ) { m_cutouts.push_back( hole ); } else { std::ostringstream ostr; ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; ostr << " * could not create board cutout\n"; wxLogMessage( "%s\n", ostr.str().c_str() ); } } oln.Clear(); if( !m_curves.empty() ) { oln.AddSegment( m_curves.front() ); m_curves.pop_front(); } continue; } std::list< KICADCURVE >::iterator sC = m_curves.begin(); std::list< KICADCURVE >::iterator eC = m_curves.end(); while( sC != eC ) { if( oln.AddSegment( *sC ) ) { m_curves.erase( sC ); break; } ++sC; } if( sC == eC && !oln.m_curves.empty() ) { std::ostringstream ostr; ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; ostr << " * could not close outline (dropping outline data with " << oln.m_curves.size() << " segments)\n"; wxLogMessage( "%s\n", ostr.str().c_str() ); oln.Clear(); if( !m_curves.empty() ) { oln.AddSegment( m_curves.front() ); m_curves.pop_front(); } } } if( oln.IsClosed() ) { if( board.IsNull() ) { if( !oln.MakeShape( board, m_thickness ) ) { std::ostringstream ostr; ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; ostr << " * could not create board extrusion\n"; wxLogMessage( "%s\n", ostr.str().c_str() ); return false; } } else { TopoDS_Shape hole; if( oln.MakeShape( hole, m_thickness ) ) { m_cutouts.push_back( hole ); } else { std::ostringstream ostr; ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n"; ostr << " * could not create board cutout\n"; wxLogMessage( "%s\n", ostr.str().c_str() ); } } } // subtract cutouts (if any) for( auto i : m_cutouts ) board = BRepAlgoAPI_Cut( board, i ); // push the board to the data structure m_pcb_label = m_assy->AddComponent( m_assy_label, board ); if( m_pcb_label.IsNull() ) return false; // color the PCB Handle(XCAFDoc_ColorTool) color = XCAFDoc_DocumentTool::ColorTool( m_doc->Main () ); Quantity_Color pcb_green( 0.06, 0.4, 0.06, Quantity_TOC_RGB ); color->SetColor( m_pcb_label, pcb_green, XCAFDoc_ColorSurf ); TopExp_Explorer topex; topex.Init( m_assy->GetShape( m_pcb_label ), TopAbs_SOLID ); while( topex.More() ) { color->SetColor( topex.Current(), pcb_green, XCAFDoc_ColorSurf ); topex.Next(); } return true; }
int main() { // The IfcHierarchyHelper is a subclass of the regular IfcFile that provides several // convenience functions for working with geometry in IFC files. IfcHierarchyHelper file; file.header().file_name().name("IfcAdvancedHouse.ifc"); IfcSchema::IfcBuilding* building = file.addBuilding(); // By adding a building, a hierarchy has been automatically created that consists of the following // structure: IfcProject > IfcSite > IfcBuilding // Lateron changing the name of the IfcProject can be done by obtaining a reference to the // project, which has been created automatically. file.getSingle<IfcSchema::IfcProject>()->setName("IfcOpenHouse"); // To demonstrate the ability to serialize arbitrary opencascade solids a building envelope is // constructed by applying boolean operations. Naturally, in IFC, building elements should be // modeled separately, with rich parametric and relational semantics. Creating geometry in this // way does not preserve any history and is merely a demonstration of technical capabilities. TopoDS_Shape outer = BRepPrimAPI_MakeBox(gp_Pnt(-5000., -180., -2000.), gp_Pnt(5000., 5180., 3000.)).Shape(); TopoDS_Shape inner = BRepPrimAPI_MakeBox(gp_Pnt(-4640., 180., 0.), gp_Pnt(4640., 4820., 3000.)).Shape(); TopoDS_Shape window1 = BRepPrimAPI_MakeBox(gp_Pnt(-5000., -180., 400.), gp_Pnt( 500., 1180., 2000.)).Shape(); TopoDS_Shape window2 = BRepPrimAPI_MakeBox(gp_Pnt( 2070., -180., 400.), gp_Pnt(3930., 180., 2000.)).Shape(); TopoDS_Shape building_shell = BRepAlgoAPI_Cut( BRepAlgoAPI_Cut( BRepAlgoAPI_Cut(outer, inner), window1 ), window2 ); // Since the solid consists only of planar faces and straight edges it can be serialized as an // IfcFacetedBRep. If it would not be a polyhedron, serialise() can only be successful when linked // to the IFC4 model and with `advanced` set to `true` which introduces IfcAdvancedFace. It would // return `0` otherwise. IfcSchema::IfcProductDefinitionShape* building_shape = IfcGeom::serialise(building_shell, false); file.addEntity(building_shape); IfcSchema::IfcRepresentation* rep = *building_shape->Representations()->begin(); rep->setContextOfItems(file.getRepresentationContext("model")); building->setRepresentation(building_shape); // A pale white colour is assigned to the building. file.setSurfaceColour( building_shape, 0.75, 0.73, 0.68); // For the ground mesh of the IfcSite we will use a Nurbs surface created in Open Cascade. Only // in IFC4 the surface can be directly serialized. In IFC2X3 the it will have to be tesselated. TopoDS_Shape shape; createGroundShape(shape); IfcSchema::IfcProductDefinitionShape* ground_representation = IfcGeom::serialise(shape, true); if (!ground_representation) { ground_representation = IfcGeom::tesselate(shape, 100.); } file.getSingle<IfcSchema::IfcSite>()->setRepresentation(ground_representation); IfcSchema::IfcRepresentation::list::ptr ground_reps = file.getSingle<IfcSchema::IfcSite>()->Representation()->Representations(); for (IfcSchema::IfcRepresentation::list::it it = ground_reps->begin(); it != ground_reps->end(); ++it) { (*it)->setContextOfItems(file.getRepresentationContext("Model")); } file.addEntity(ground_representation); file.setSurfaceColour(ground_representation, 0.15, 0.25, 0.05); /* // Note that IFC lacks elementary surfaces that STEP does have, such as spherical_surface. // BRepBuilderAPI_NurbsConvert can be used to serialize such surfaces as nurbs surfaces. TopoDS_Shape sphere = BRepPrimAPI_MakeSphere(gp_Pnt(), 1000.).Shape(); IfcSchema::IfcProductDefinitionShape* sphere_representation = IfcGeom::serialise(sphere, true); if (S(IfcSchema::Identifier) == "IFC4") { sphere = BRepBuilderAPI_NurbsConvert(sphere, true).Shape(); sphere_representation = IfcGeom::serialise(sphere, true); } */ // Finally create a file stream for our output and write the IFC file to it. std::ofstream f("IfcAdvancedHouse.ifc"); f << file; }
PNamedShape CTiglFusePlane::FuseWithChilds(CTiglAbstractPhysicalComponent* parent) { assert(parent != NULL); PNamedShape parentShape (parent->GetLoft()); if (parentShape) { if (_mymode == FULL_PLANE || _mymode == FULL_PLANE_TRIMMED_FF) { PNamedShape rootShapeMirr = parent->GetMirroredLoft(); parentShape = CMergeShapes(parentShape, rootShapeMirr); } } CTiglAbstractPhysicalComponent::ChildContainerType childs = parent->GetChildren(false); CTiglAbstractPhysicalComponent::ChildContainerType::iterator childIt; if (childs.size() == 0) { return parentShape; } ListPNamedShape childShapes; for (childIt = childs.begin(); childIt != childs.end(); ++childIt) { CTiglAbstractPhysicalComponent* child = *childIt; if (!child) { continue; } PNamedShape childShape = FuseWithChilds(child); childShapes.push_back(childShape); } CFuseShapes fuser(parentShape, childShapes); PNamedShape result = fuser.NamedShape(); // trim previous intersections ListPNamedShape::iterator intIt = _intersections.begin(); ListPNamedShape newInts; for (; intIt != _intersections.end(); ++intIt) { PNamedShape inters = *intIt; if (!inters) { continue; } TopoDS_Shape sh = inters->Shape(); if (parentShape) { sh = BRepAlgoAPI_Cut(sh, parentShape->Shape()); } if (!sh.IsNull()) { inters->SetShape(sh); newInts.push_back(inters); } } _intersections = newInts; // insert intersections ListPNamedShape::const_iterator it = fuser.Intersections().begin(); for (; it != fuser.Intersections().end(); it++) { if (*it) { _intersections.push_back(*it); } } return result; }