Back to index

salome-geom  6.5.0
Public Member Functions | Static Public Member Functions | Friends
GEOMImpl_ProjectionDriver Class Reference

#include <GEOMImpl_ProjectionDriver.hxx>

List of all members.

Public Member Functions

void * operator new (size_t, void *anAddress)
void * operator new (size_t size)
void operator delete (void *anAddress)
Standard_EXPORT GEOMImpl_ProjectionDriver ()
virtual Standard_EXPORT
Standard_Integer 
Execute (TFunction_Logbook &log) const
virtual Standard_EXPORT void Validate (TFunction_Logbook &) const
Standard_EXPORT Standard_Boolean MustExecute (const TFunction_Logbook &) const
Standard_EXPORT ~GEOMImpl_ProjectionDriver ()
Standard_EXPORT const Handle (Standard_Type)&DynamicType() const
Standard_EXPORT Standard_Boolean IsKind (const Handle(Standard_Type)&AType) const

Static Public Member Functions

static Standard_EXPORT const
Standard_GUID & 
GetID ()

Friends

Standard_EXPORT friend
Handle_Standard_Type & 
GEOMImpl_ProjectionDriver_Type_ ()

Detailed Description

Definition at line 125 of file GEOMImpl_ProjectionDriver.hxx.


Constructor & Destructor Documentation

Definition at line 70 of file GEOMImpl_ProjectionDriver.cxx.

{
}

Definition at line 149 of file GEOMImpl_ProjectionDriver.hxx.

{};

Member Function Documentation

Standard_Integer GEOMImpl_ProjectionDriver::Execute ( TFunction_Logbook &  log) const [virtual]

Definition at line 78 of file GEOMImpl_ProjectionDriver.cxx.

{
  if (Label().IsNull())  return 0;    
  Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());

  if (aFunction.IsNull()) return 0;

  TopoDS_Shape aShape;
  gp_Trsf aTrsf;

  GEOMImpl_IMirror TI (aFunction);
  Standard_Integer aType = aFunction->GetType();

  Handle(GEOM_Function) anOriginalFunction = TI.GetOriginal();
  if (anOriginalFunction.IsNull()) return 0;

  TopoDS_Shape anOriginal = anOriginalFunction->GetValue();
  if (anOriginal.IsNull()) return 0;

  // Projection
  if (aType == PROJECTION_COPY) {
    // Source shape (point, edge or wire)
    if (anOriginal.ShapeType() != TopAbs_VERTEX &&
        anOriginal.ShapeType() != TopAbs_EDGE &&
        anOriginal.ShapeType() != TopAbs_WIRE) {
      Standard_ConstructionError::Raise
        ("Projection aborted : the source shape is neither a vertex, nor an edge or a wire");
    }

    // Target face
    Handle(GEOM_Function) aTargetFunction = TI.GetPlane();
    if (aTargetFunction.IsNull()) return 0;
    TopoDS_Shape aFaceShape = aTargetFunction->GetValue();
    //if (aFaceShape.IsNull() || aFaceShape.ShapeType() != TopAbs_FACE) {
    //  Standard_ConstructionError::Raise
    //    ("Projection aborted : the target shape is not a face");
    //}

    Standard_Real tol = 1.e-4;        

    if (anOriginal.ShapeType() == TopAbs_VERTEX) {
      if (aFaceShape.IsNull() || aFaceShape.ShapeType() != TopAbs_FACE) {
        Standard_ConstructionError::Raise
          ("Projection aborted : the target shape is not a face");
      }
      TopoDS_Face aFace = TopoDS::Face(aFaceShape);
      Handle(Geom_Surface) surface = BRep_Tool::Surface(aFace);
      double U1, U2, V1, V2;
      //surface->Bounds(U1, U2, V1, V2);
      BRepTools::UVBounds(aFace, U1, U2, V1, V2);

      // projector
      GeomAPI_ProjectPointOnSurf proj;
      proj.Init(surface, U1, U2, V1, V2, tol);

      gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(anOriginal));
      proj.Perform(aPnt);
      if (!proj.IsDone()) {
        Standard_ConstructionError::Raise
          ("Projection aborted : the algorithm failed");
      }
      int nbPoints = proj.NbPoints();
      if (nbPoints < 1) {
        Standard_ConstructionError::Raise("No solution found");
      }

      Quantity_Parameter U, V;
      proj.LowerDistanceParameters(U, V);
      gp_Pnt2d aProjPnt (U, V);

      // classifier
      BRepClass_FaceClassifier aClsf (aFace, aProjPnt, tol);
      if (aClsf.State() != TopAbs_IN && aClsf.State() != TopAbs_ON) {
        bool isSol = false;
        double minDist = RealLast();
        for (int i = 1; i <= nbPoints; i++) {
          Quantity_Parameter Ui, Vi;
          proj.Parameters(i, Ui, Vi);
          aProjPnt = gp_Pnt2d(Ui, Vi);
          aClsf.Perform(aFace, aProjPnt, tol);
          if (aClsf.State() == TopAbs_IN || aClsf.State() == TopAbs_ON) {
            isSol = true;
            double dist = proj.Distance(i);
            if (dist < minDist) {
              minDist = dist;
              U = Ui;
              V = Vi;
            }
          }
        }
        if (!isSol) {
          Standard_ConstructionError::Raise("No solution found");
        }
      }

      gp_Pnt surfPnt = surface->Value(U, V);

      aShape = BRepBuilderAPI_MakeVertex(surfPnt).Shape();
    }
    else {
      //see BRepTest_BasicCommands.cxx for example of BRepOffsetAPI_NormalProjection
      BRepOffsetAPI_NormalProjection OrtProj (aFaceShape);
      OrtProj.Add(anOriginal);

      //Standard_Real tol = 1.e-4;        
      //Standard_Real tol2d = Pow(tol, 2./3);
      //GeomAbs_Shape Continuity = GeomAbs_C2;  
      //Standard_Integer MaxDeg = 14;           
      //Standard_Integer MaxSeg = 16;           
      //OrtProj.SetParams(tol, tol2d, Continuity, MaxDeg, MaxSeg);
      try {
        OrtProj.Build();
      } catch (Standard_Failure) {
        Handle(Standard_Failure) aFail = Standard_Failure::Caught();
        TCollection_AsciiString aMsg (aFail->GetMessageString());
        if (!aMsg.Length())
          aMsg = "Projection aborted : possibly the source shape intersects the cylinder's axis";
        Standard_ConstructionError::Raise(aMsg.ToCString());
      }
      if (!OrtProj.IsDone()) {
        Standard_ConstructionError::Raise
          ("Projection aborted : BRepOffsetAPI_NormalProjection failed");
      }

      aShape = OrtProj.Shape();

      // check that the result shape is an empty compound
      // (IPAL22905: TC650: Projection on face dialog problems)
      if( !aShape.IsNull() && aShape.ShapeType() == TopAbs_COMPOUND )
      {
        TopoDS_Iterator anIter( aShape );
        if( !anIter.More() )
          Standard_ConstructionError::Raise("Projection aborted : empty compound produced");
      }
    }

    if (aShape.IsNull()) return 0;

    aFunction->SetValue(aShape);
    log.SetTouched(Label()); 
  }

  return 1;
}

Here is the call graph for this function:

const Standard_GUID & GEOMImpl_ProjectionDriver::GetID ( ) [static]

Definition at line 58 of file GEOMImpl_ProjectionDriver.cxx.

{
  static Standard_GUID aProjectionDriver ("FF1BBB70-5D14-4df2-980B-3A668264EA16");
  return aProjectionDriver; 
}
Standard_EXPORT const GEOMImpl_ProjectionDriver::Handle ( Standard_Type  ) const [inline]

Definition at line 155 of file GEOMImpl_ProjectionDriver.hxx.

Here is the call graph for this function:

Here is the caller graph for this function:

Standard_EXPORT Standard_Boolean GEOMImpl_ProjectionDriver::IsKind ( const Handle(Standard_Type)&  AType) const [inline]

Definition at line 156 of file GEOMImpl_ProjectionDriver.hxx.

{ return (STANDARD_TYPE(GEOMImpl_ProjectionDriver) == AType || TFunction_Driver::IsKind(AType)); } 

Here is the call graph for this function:

Standard_EXPORT Standard_Boolean GEOMImpl_ProjectionDriver::MustExecute ( const TFunction_Logbook &  ) const [inline]

Definition at line 147 of file GEOMImpl_ProjectionDriver.hxx.

{ return Standard_True; }
void GEOMImpl_ProjectionDriver::operator delete ( void *  anAddress) [inline]

Definition at line 137 of file GEOMImpl_ProjectionDriver.hxx.

      { 
        if (anAddress) Standard::Free((Standard_Address&)anAddress); 
      }
void* GEOMImpl_ProjectionDriver::operator new ( size_t  ,
void *  anAddress 
) [inline]

Definition at line 129 of file GEOMImpl_ProjectionDriver.hxx.

      {
        return anAddress;
      }
void* GEOMImpl_ProjectionDriver::operator new ( size_t  size) [inline]

Definition at line 133 of file GEOMImpl_ProjectionDriver.hxx.

      { 
        return Standard::Allocate(size); 
      }
virtual Standard_EXPORT void GEOMImpl_ProjectionDriver::Validate ( TFunction_Logbook &  ) const [inline, virtual]

Definition at line 146 of file GEOMImpl_ProjectionDriver.hxx.

{}

Friends And Related Function Documentation

Standard_EXPORT friend Handle_Standard_Type& GEOMImpl_ProjectionDriver_Type_ ( ) [friend]

Definition at line 228 of file GEOMImpl_ProjectionDriver.cxx.

{

  static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
  if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
  static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
  if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); 
  static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
  if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
 

  static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
  static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ProjectionDriver",
                                                         sizeof(GEOMImpl_ProjectionDriver),
                                                         1,
                                                         (Standard_Address)_Ancestors,
                                                         (Standard_Address)NULL);

  return _aType;
}

The documentation for this class was generated from the following files: