//---------------------------------------------------------------- // Function: transform // Description: transform the body and its child entities // use a transform matrix // // Author: Jane Hu //---------------------------------------------------------------- CubitStatus OCCBody::transform(BRepBuilderAPI_Transform& aBRepTrsf) { TopoDS_Shape * shape; get_TopoDS_Shape(shape); aBRepTrsf.Perform(*shape); update_OCC_entity(&aBRepTrsf); // calculate for bounding box update_bounding_box(); return CUBIT_SUCCESS; }
//======================================================================= //function : Execute //purpose : //======================================================================= Standard_Integer GEOMImpl_ScaleDriver::Execute(TFunction_Logbook& log) const { if (Label().IsNull()) return 0; Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label()); GEOMImpl_IScale aCI (aFunction); Standard_Integer aType = aFunction->GetType(); TopoDS_Shape aShape; if (aType == SCALE_SHAPE || aType == SCALE_SHAPE_COPY) { Handle(GEOM_Function) aRefShape = aCI.GetShape(); TopoDS_Shape aShapeBase = aRefShape->GetValue(); if (aShapeBase.IsNull()) return 0; gp_Pnt aP (0,0,0); Handle(GEOM_Function) aRefPoint = aCI.GetPoint(); if (!aRefPoint.IsNull()) { TopoDS_Shape aShapePnt = aRefPoint->GetValue(); if (aShapePnt.IsNull()) return 0; if (aShapePnt.ShapeType() != TopAbs_VERTEX) return 0; aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt)); } // Bug 6839: Check for standalone (not included in faces) degenerated edges TopTools_IndexedDataMapOfShapeListOfShape aEFMap; TopExp::MapShapesAndAncestors(aShapeBase, TopAbs_EDGE, TopAbs_FACE, aEFMap); Standard_Integer i, nbE = aEFMap.Extent(); for (i = 1; i <= nbE; i++) { TopoDS_Shape anEdgeSh = aEFMap.FindKey(i); if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeSh))) { const TopTools_ListOfShape& aFaces = aEFMap.FindFromIndex(i); if (aFaces.IsEmpty()) Standard_ConstructionError::Raise ("Scaling aborted : cannot scale standalone degenerated edge"); } } // Perform Scaling gp_Trsf aTrsf; aTrsf.SetScale(aP, aCI.GetFactor()); BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False); aShape = aBRepTrsf.Shape(); } else if (aType == SCALE_SHAPE_AFFINE || aType == SCALE_SHAPE_AFFINE_COPY) { Handle(GEOM_Function) aRefShape = aCI.GetShape(); Handle(GEOM_Function) aRefVector = aCI.GetVector(); TopoDS_Shape aShapeBase = aRefShape->GetValue(); TopoDS_Shape aShapeVector = aRefVector->GetValue(); if (aShapeBase.IsNull() || aShapeVector.IsNull()) return 0; if (aShapeVector.ShapeType() != TopAbs_EDGE) return 0; TopoDS_Edge anEdgeVector = TopoDS::Edge(aShapeVector); // Bug 6839: Check for standalone (not included in faces) degenerated edges TopTools_IndexedDataMapOfShapeListOfShape aEFMap; TopExp::MapShapesAndAncestors(aShapeBase, TopAbs_EDGE, TopAbs_FACE, aEFMap); Standard_Integer i, nbE = aEFMap.Extent(); for (i = 1; i <= nbE; i++) { TopoDS_Shape anEdgeSh = aEFMap.FindKey(i); if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeSh))) { const TopTools_ListOfShape& aFaces = aEFMap.FindFromIndex(i); if (aFaces.IsEmpty()) Standard_ConstructionError::Raise ("Scaling aborted : cannot scale standalone degenerated edge"); } } //Get axis gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdgeVector)); gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(anEdgeVector)); gp_Dir aDir(gp_Vec(aP1, aP2)); gp_Ax2 anAx2(aP1, aDir); // Perform Scaling gp_GTrsf aGTrsf; aGTrsf.SetAffinity(anAx2, aCI.GetFactor()); BRepBuilderAPI_GTransform aBRepGTrsf(aShapeBase, aGTrsf, Standard_False); aShape = aBRepGTrsf.Shape(); } else if (aType == SCALE_SHAPE_AXES || aType == SCALE_SHAPE_AXES_COPY) { Handle(GEOM_Function) aRefShape = aCI.GetShape(); TopoDS_Shape aShapeBase = aRefShape->GetValue(); if (aShapeBase.IsNull()) return 0; bool isP = false; gp_Pnt aP (0,0,0); Handle(GEOM_Function) aRefPoint = aCI.GetPoint(); if (!aRefPoint.IsNull()) { TopoDS_Shape aShapePnt = aRefPoint->GetValue(); if (aShapePnt.IsNull()) return 0; if (aShapePnt.ShapeType() != TopAbs_VERTEX) return 0; aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt)); isP = true; } // Bug 6839: Check for standalone (not included in faces) degenerated edges TopTools_IndexedDataMapOfShapeListOfShape aEFMap; TopExp::MapShapesAndAncestors(aShapeBase, TopAbs_EDGE, TopAbs_FACE, aEFMap); Standard_Integer i, nbE = aEFMap.Extent(); for (i = 1; i <= nbE; i++) { TopoDS_Shape anEdgeSh = aEFMap.FindKey(i); if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeSh))) { const TopTools_ListOfShape& aFaces = aEFMap.FindFromIndex(i); if (aFaces.IsEmpty()) Standard_ConstructionError::Raise ("Scaling aborted : cannot scale standalone degenerated edge"); } } // Perform Scaling gp_GTrsf aGTrsf; gp_Mat rot (aCI.GetFactorX(), 0, 0, 0, aCI.GetFactorY(), 0, 0, 0, aCI.GetFactorZ()); aGTrsf.SetVectorialPart(rot); if (isP) { gp_Pnt anO (0,0,0); if (anO.Distance(aP) > Precision::Confusion()) { gp_GTrsf aGTrsfP0; aGTrsfP0.SetTranslationPart(anO.XYZ() - aP.XYZ()); gp_GTrsf aGTrsf0P; aGTrsf0P.SetTranslationPart(aP.XYZ()); //aGTrsf = aGTrsf0P * aGTrsf * aGTrsfP0; aGTrsf = aGTrsf0P.Multiplied(aGTrsf); aGTrsf = aGTrsf.Multiplied(aGTrsfP0); } } BRepBuilderAPI_GTransform aBRepGTrsf (aShapeBase, aGTrsf, Standard_False); if (!aBRepGTrsf.IsDone()) Standard_ConstructionError::Raise("Scaling not done"); aShape = aBRepGTrsf.Shape(); } else { } if (aShape.IsNull()) return 0; // Check shape validity BRepCheck_Analyzer ana (aShape, false); if (!ana.IsValid()) { ShapeFix_ShapeTolerance aSFT; aSFT.LimitTolerance(aShape,Precision::Confusion(),Precision::Confusion()); Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape(aShape); aSfs->SetPrecision(Precision::Confusion()); aSfs->Perform(); aShape = aSfs->Shape(); ana.Init(aShape, Standard_False); if (!ana.IsValid()) { Standard_CString anErrStr("Scaling aborted : non valid shape result"); #ifdef THROW_ON_INVALID_SH Standard_ConstructionError::Raise(anErrStr); #else MESSAGE(anErrStr); //further processing can be performed here //... //in case of failure of automatic treatment //mark the corresponding GEOM_Object as problematic TDF_Label aLabel = aFunction->GetOwnerEntry(); if (!aLabel.IsRoot()) { Handle(GEOM_Object) aMainObj = GEOM_Object::GetObject(aLabel); if (!aMainObj.IsNull()) aMainObj->SetDirty(Standard_True); } #endif } } aFunction->SetValue(aShape); log.SetTouched(Label()); return 1; }
//======================================================================= //function : MakeScaledPrism //purpose : //======================================================================= TopoDS_Shape GEOMImpl_PrismDriver::MakeScaledPrism (const TopoDS_Shape& theShapeBase, const gp_Vec& theVector, const Standard_Real theScaleFactor, const gp_Pnt& theCDG, bool isCDG) { TopoDS_Shape aShape; BRep_Builder B; // 1. aCDG = geompy.MakeCDG(theBase) gp_Pnt aCDG = theCDG; if (!isCDG) { gp_Ax3 aPos = GEOMImpl_IMeasureOperations::GetPosition(theShapeBase); aCDG = aPos.Location(); } TopoDS_Shape aShapeCDG_1 = BRepBuilderAPI_MakeVertex(aCDG).Shape(); // Process case of several given shapes if (theShapeBase.ShapeType() == TopAbs_COMPOUND || theShapeBase.ShapeType() == TopAbs_SHELL) { int nbSub = 0; TopoDS_Shape aShapeI; TopoDS_Compound aCompound; B.MakeCompound(aCompound); TopoDS_Iterator It (theShapeBase, Standard_True, Standard_True); for (; It.More(); It.Next()) { nbSub++; aShapeI = MakeScaledPrism(It.Value(), theVector, theScaleFactor, aCDG, true); B.Add(aCompound, aShapeI); } if (nbSub == 1) aShape = aShapeI; else if (nbSub > 1) aShape = GEOMImpl_GlueDriver::GlueFaces(aCompound, Precision::Confusion(), Standard_True); return aShape; } // 2. Scale = geompy.MakeScaleTransform(theBase, aCDG, theScaleFactor) // Bug 6839: Check for standalone (not included in faces) degenerated edges TopTools_IndexedDataMapOfShapeListOfShape aEFMap; TopExp::MapShapesAndAncestors(theShapeBase, TopAbs_EDGE, TopAbs_FACE, aEFMap); Standard_Integer i, nbE = aEFMap.Extent(); for (i = 1; i <= nbE; i++) { TopoDS_Shape anEdgeSh = aEFMap.FindKey(i); if (BRep_Tool::Degenerated(TopoDS::Edge(anEdgeSh))) { const TopTools_ListOfShape& aFaces = aEFMap.FindFromIndex(i); if (aFaces.IsEmpty()) Standard_ConstructionError::Raise ("Scaling aborted : cannot scale standalone degenerated edge"); } } // Perform Scaling gp_Trsf aTrsf; aTrsf.SetScale(aCDG, theScaleFactor); BRepBuilderAPI_Transform aBRepTrsf (theShapeBase, aTrsf, Standard_False); TopoDS_Shape aScale = aBRepTrsf.Shape(); // 3. aBase2 = geompy.MakeTranslationVectorDistance(Scale, theVec, theH) gp_Trsf aTrsf3; aTrsf3.SetTranslation(theVector); TopLoc_Location aLocOrig = aScale.Location(); gp_Trsf aTrsfOrig = aLocOrig.Transformation(); TopLoc_Location aLocRes (aTrsf3 * aTrsfOrig); TopoDS_Shape aBase2 = aScale.Located(aLocRes); // 4. aCDG_2 = geompy.MakeTranslationVectorDistance(aCDG, theVec, theH) gp_Pnt aCDG_2 = aCDG.Translated(theVector); TopoDS_Shape aShapeCDG_2 = BRepBuilderAPI_MakeVertex(aCDG_2).Shape(); // 5. Vector = geompy.MakeVector(aCDG, aCDG_2) TopoDS_Shape aShapeVec = BRepBuilderAPI_MakeEdge(aCDG, aCDG_2).Shape(); TopoDS_Edge anEdge = TopoDS::Edge(aShapeVec); TopoDS_Wire aWirePath = BRepBuilderAPI_MakeWire(anEdge); // 6. aPrism = geompy.MakePipeWithDifferentSections([theBase, aBase2], [aCDG, aCDG_2], Vector, False, False) Handle(TopTools_HSequenceOfShape) aBases = new TopTools_HSequenceOfShape; aBases->Append(theShapeBase); aBases->Append(aBase2); Handle(TopTools_HSequenceOfShape) aLocs = new TopTools_HSequenceOfShape; aLocs->Append(aShapeCDG_1); aLocs->Append(aShapeCDG_2); aShape = GEOMImpl_PipeDriver::CreatePipeWithDifferentSections(aWirePath, aBases, aLocs, false, false); // 7. Make a solid, if possible if (theShapeBase.ShapeType() == TopAbs_FACE) { BRepBuilderAPI_Sewing aSewing (Precision::Confusion()*10.0); TopExp_Explorer expF (aShape, TopAbs_FACE); Standard_Integer ifa = 0; for (; expF.More(); expF.Next()) { aSewing.Add(expF.Current()); ifa++; } if (ifa > 0) { aSewing.Perform(); TopoDS_Shape aShell; TopoDS_Shape sh = aSewing.SewedShape(); if (sh.ShapeType() == TopAbs_FACE && ifa == 1) { // case for creation of shell from one face TopoDS_Shell ss; B.MakeShell(ss); B.Add(ss,sh); aShell = ss; } else { TopExp_Explorer exp (sh, TopAbs_SHELL); Standard_Integer ish = 0; for (; exp.More(); exp.Next()) { aShell = exp.Current(); ish++; } if (ish != 1) aShell = sh; } BRepCheck_Shell chkShell (TopoDS::Shell(aShell)); if (chkShell.Closed() == BRepCheck_NoError) { TopoDS_Solid Sol; B.MakeSolid(Sol); B.Add(Sol, aShell); BRepClass3d_SolidClassifier SC (Sol); SC.PerformInfinitePoint(Precision::Confusion()); if (SC.State() == TopAbs_IN) { B.MakeSolid(Sol); B.Add(Sol, aShell.Reversed()); } aShape = Sol; } } } return aShape; }
//======================================================================= //function : Execute //purpose : //======================================================================= Standard_Integer GEOMImpl_PositionDriver::Execute(TFunction_Logbook& log) const { if (Label().IsNull()) return 0; Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label()); GEOMImpl_IPosition aCI (aFunction); Standard_Integer aType = aFunction->GetType(); TopoDS_Shape aShape; if (aType == POSITION_SHAPE || aType == POSITION_SHAPE_COPY) { Handle(GEOM_Function) aRefShape = aCI.GetShape(); Handle(GEOM_Function) aRefStartLCS = aCI.GetStartLCS(); Handle(GEOM_Function) aRefEndLCS = aCI.GetEndLCS(); TopoDS_Shape aShapeBase = aRefShape->GetValue(); TopoDS_Shape aShapeStartLCS = aRefStartLCS->GetValue(); TopoDS_Shape aShapeEndLCS = aRefEndLCS->GetValue(); if (aShapeBase.IsNull() || aShapeStartLCS.IsNull() || aShapeEndLCS.IsNull() || aShapeEndLCS.ShapeType() != TopAbs_FACE) return 0; gp_Trsf aTrsf; gp_Ax3 aStartAx3, aDestAx3; // End LCS aDestAx3 = GEOMImpl_IMeasureOperations::GetPosition(aShapeEndLCS); // Start LCS aStartAx3 = GEOMImpl_IMeasureOperations::GetPosition(aShapeStartLCS); // Set transformation aTrsf.SetDisplacement(aStartAx3, aDestAx3); // Perform transformation BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False); aShape = aBRepTrsf.Shape(); } else if (aType == POSITION_SHAPE_FROM_GLOBAL || aType == POSITION_SHAPE_FROM_GLOBAL_COPY) { Handle(GEOM_Function) aRefShape = aCI.GetShape(); Handle(GEOM_Function) aRefEndLCS = aCI.GetEndLCS(); TopoDS_Shape aShapeBase = aRefShape->GetValue(); TopoDS_Shape aShapeEndLCS = aRefEndLCS->GetValue(); if (aShapeBase.IsNull() || aShapeEndLCS.IsNull() || aShapeEndLCS.ShapeType() != TopAbs_FACE) return 0; gp_Trsf aTrsf; gp_Ax3 aStartAx3, aDestAx3; // End LCS aDestAx3 = GEOMImpl_IMeasureOperations::GetPosition(aShapeEndLCS); // Set transformation aTrsf.SetDisplacement(aStartAx3, aDestAx3); // Perform transformation BRepBuilderAPI_Transform aBRepTrsf (aShapeBase, aTrsf, Standard_False); aShape = aBRepTrsf.Shape(); } else if (aType == POSITION_ALONG_PATH) { Handle(GEOM_Function) aRefShape = aCI.GetShape(); Handle(GEOM_Function) aPathShape = aCI.GetPath(); Standard_Real aParameter = aCI.GetDistance(); bool aReversed = aCI.GetReverse(); if (aReversed) aParameter = 1 - aParameter; TopoDS_Shape aShapeBase = aRefShape->GetValue(); TopoDS_Shape aPath = aPathShape->GetValue(); TopoDS_Wire aWire; if (aShapeBase.IsNull() || aPath.IsNull()) return 0; if ( aPath.ShapeType() == TopAbs_EDGE ) { TopoDS_Edge anEdge = TopoDS::Edge(aPath); aWire = BRepBuilderAPI_MakeWire(anEdge); } else if ( aPath.ShapeType() == TopAbs_WIRE) aWire = TopoDS::Wire(aPath); else return 0; Handle(GeomFill_TrihedronLaw) TLaw = new GeomFill_CorrectedFrenet(); Handle(GeomFill_CurveAndTrihedron) aLocationLaw = new GeomFill_CurveAndTrihedron( TLaw ); Handle(BRepFill_LocationLaw) aLocation = new BRepFill_Edge3DLaw(aWire, aLocationLaw); aLocation->TransformInCompatibleLaw( 0.01 ); //Calculate a Parameter Standard_Real aFirstParam1 = 0, aLastParam1 = 0; // Parameters of the First edge Standard_Real aFirstParam2 = 0, aLastParam2 = 0; // Parameters of the Last edge aLocation->CurvilinearBounds(aLocation->NbLaw(), aFirstParam2, aLastParam2); if ( aLocation->NbLaw() > 1) aLocation->CurvilinearBounds(1, aFirstParam1, aLastParam1); else if ( aLocation->NbLaw() == 1 ) aFirstParam1 = aFirstParam2; else return 0; Standard_Real aParam = (aFirstParam1 + (aLastParam2 - aFirstParam1)*aParameter ); TopoDS_Shape CopyShape = aShapeBase; BRepFill_SectionPlacement Place( aLocation, aShapeBase ); TopLoc_Location Loc2(Place.Transformation()), Loc1; Loc1 = CopyShape.Location(); CopyShape.Location(Loc2.Multiplied(Loc1)); aLocation->D0( aParam, CopyShape ); aShape = CopyShape; } else return 0; if (aShape.IsNull()) return 0; aFunction->SetValue(aShape); log.SetTouched(Label()); return 1; }