Пример #1
0
TEST(BSplines, pointsToLinear)
{
    std::vector<gp_Pnt> points;
    points.push_back(gp_Pnt(0,0,0));
    points.push_back(gp_Pnt(2,0,0));
    points.push_back(gp_Pnt(2,1,0));
    points.push_back(gp_Pnt(1,1,0));
    
    Handle(Geom_BSplineCurve) curve;
    ASSERT_NO_THROW(curve = tigl::CPointsToLinearBSpline(points));
    
    ASSERT_NEAR(0, curve->Value(0.  ).Distance(gp_Pnt(0,0,0)), 1e-10);
    ASSERT_NEAR(0, curve->Value(0.5 ).Distance(gp_Pnt(2,0,0)), 1e-10);
    ASSERT_NEAR(0, curve->Value(0.75).Distance(gp_Pnt(2,1,0)), 1e-10);
    ASSERT_NEAR(0, curve->Value(1.  ).Distance(gp_Pnt(1,1,0)), 1e-10);
    
    gp_Pnt p; gp_Vec v;
    curve->D1(0.25, p, v);
    ASSERT_NEAR(v.Magnitude(), v*gp_Vec(1,0,0), 1e-10);
    
    curve->D1(0.6, p, v);
    ASSERT_NEAR(v.Magnitude(), v*gp_Vec(0,1,0), 1e-10);
    
    curve->D1(0.8, p, v);
    ASSERT_NEAR(v.Magnitude(), v*gp_Vec(-1,0,0), 1e-10);
}
Пример #2
0
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);
}
Пример #3
0
bool IfcGeom::Kernel::convert(const IfcSchema::IfcPolygonalBoundedHalfSpace* l, TopoDS_Shape& shape) {
	TopoDS_Shape halfspace;
	if ( ! IfcGeom::Kernel::convert((IfcSchema::IfcHalfSpaceSolid*)l,halfspace) ) return false;	
	
	TopoDS_Wire wire;
	if ( ! convert_wire(l->PolygonalBoundary(),wire) || ! wire.Closed() ) return false;
	
	gp_Trsf trsf;
	if ( ! convert(l->Position(),trsf) ) return false;

	TColgp_SequenceOfPnt points;
	if (wire_to_sequence_of_point(wire, points)) {
		remove_duplicate_points_from_loop(points, wire.Closed()); // Note: wire always closed, as per if statement above
		remove_collinear_points_from_loop(points, wire.Closed());
		sequence_of_point_to_wire(points, wire, wire.Closed());
	}

	TopoDS_Shape prism = BRepPrimAPI_MakePrism(BRepBuilderAPI_MakeFace(wire),gp_Vec(0,0,200));
	gp_Trsf down; down.SetTranslation(gp_Vec(0,0,-100.0));
	
	// `trsf` and `down` both have a unit scale factor
	prism.Move(trsf*down);	
	
	shape = BRepAlgoAPI_Common(halfspace,prism);
	return true;
}
Пример #4
0
void HeeksDxfRead::OnReadText(const double *point, const double height,  const char* text, int hj, int vj)
{
	gp_Trsf trsf;
	trsf.SetTranslation( gp_Vec( gp_Pnt(0,0,0), gp_Pnt(point[0], point[1], point[2]) ) );
	trsf.SetScaleFactor( height * 1.7 );

	wxString txt(Ctt(text));
	txt.Replace(_T("\\P"),_T("\n"),true);
	txt.Replace(_T("%%010"),_T("\n"),true);

	int offset = 0;
	while ((txt.Length() > 0) && (txt[0] == _T('\\')) && ((offset = txt.find(_T(';'))) != -1))
	{
		txt.Remove(0, offset+1);
	}

	wxArrayString retArray;
	Split(txt, retArray, _T("\n"));

	gp_Trsf line_feed_shift;
	line_feed_shift.SetTranslationPart(gp_Vec(0, -height, 0));

	for(unsigned int i = 0; i<retArray.GetCount(); i++)
	{
		HText *new_object = new HText(trsf, retArray[i], ActiveColorPtr(m_aci),
#ifndef WIN32
			NULL, 
#endif
			hj, vj);
		AddObject(new_object);
		trsf = trsf * line_feed_shift;
	}
}
TopoDS_Wire CCPACSControlSurfaceDeviceAirfoil::GetWire(CTiglControlSurfaceBorderCoordinateSystem& coords)
{
    CCPACSWingProfile& profile =_config->GetWingProfile(_airfoilUID);
    TopoDS_Wire w = profile.GetWire();

    // scale
    CTiglTransformation scale;
    scale.AddScaling(coords.getLe().Distance(coords.getTe()), 1, _scalZ);

    // bring the wire into the coordinate system of
    // the airfoil by swapping z with y
    gp_Trsf trafo;
    trafo.SetTransformation(gp_Ax3(gp_Pnt(0,0,0), gp_Vec(0,-1,0), gp_Vec(1,0,0)));
    CTiglTransformation flipZY(trafo);

    // put the airfoil to the correct place
    CTiglTransformation position(coords.globalTransform());

    // compute the total transform
    CTiglTransformation total;
    total.PreMultiply(scale);
    total.PreMultiply(flipZY);
    total.PreMultiply(position);
    w = TopoDS::Wire(total.Transform(w));
    return w;
}
Пример #6
0
bool CFace::GetClosestPoint(const gp_Pnt &pos, gp_Pnt &closest_pnt)const{
	BRepPrimAPI_MakeBox cuboid(gp_Ax2(pos, gp_Vec(1, 0, 0), gp_Vec(0, 1, 0)), 0.0001, 0.0001, 0.0001);

	BRepExtrema_DistShapeShape extrema(m_topods_face, cuboid.Shape());
	if(extrema.Perform() != Standard_True)return false;
	closest_pnt = extrema.PointOnShape1(1);

	return true;
}
Пример #7
0
// static
bool CShape::IsMatrixDifferentialScale(const gp_Trsf& trsf)
{
	double scalex = gp_Vec(1, 0, 0).Transformed(trsf).Magnitude();
	double scaley = gp_Vec(0, 1, 0).Transformed(trsf).Magnitude();
	double scalez = gp_Vec(0, 0, 1).Transformed(trsf).Magnitude();

	if(fabs(scalex - scaley) > 0.000000000001)return true;
	if(fabs(scalex - scalez) > 0.000000000001)return true;
	return false;
}
bool PCBMODEL::getModelLocation( bool aBottom, DOUBLET aPosition, double aRotation,
    TRIPLET aOffset, TRIPLET aOrientation, TopLoc_Location& aLocation )
{
    // Order of operations:
    // a. aOrientation is applied -Z*-Y*-X
    // b. aOffset is applied
    //      Top ? add thickness to the Z offset
    // c. Bottom ? Rotate on X axis (in contrast to most ECAD which mirror on Y),
    //             then rotate on +Z
    //    Top ? rotate on -Z
    // d. aPosition is applied
    //
    // Note: Y axis is inverted in KiCad

    gp_Trsf lPos;
    lPos.SetTranslation( gp_Vec( aPosition.x, -aPosition.y, 0.0 ) );

    // offset (inches)
    aOffset.x *= 25.4;
    aOffset.y *= 25.4;
    aOffset.z *= 25.4 + BOARD_OFFSET;
    gp_Trsf lRot;

    if( aBottom )
    {
        lRot.SetRotation( gp_Ax1( gp_Pnt( 0.0, 0.0, 0.0 ), gp_Dir( 0.0, 0.0, 1.0 ) ), aRotation );
        lPos.Multiply( lRot );
        lRot.SetRotation( gp_Ax1( gp_Pnt( 0.0, 0.0, 0.0 ), gp_Dir( 1.0, 0.0, 0.0 ) ), M_PI );
        lPos.Multiply( lRot );
    }
    else
    {
        aOffset.z += m_thickness;
        lRot.SetRotation( gp_Ax1( gp_Pnt( 0.0, 0.0, 0.0 ), gp_Dir( 0.0, 0.0, 1.0 ) ), aRotation );
        lPos.Multiply( lRot );
    }

    gp_Trsf lOff;
    lOff.SetTranslation( gp_Vec( aOffset.x, aOffset.y, aOffset.z ) );
    lPos.Multiply( lOff );

    gp_Trsf lOrient;
    lOrient.SetRotation( gp_Ax1( gp_Pnt( 0.0, 0.0, 0.0 ),
       gp_Dir( 0.0, 0.0, 1.0 ) ), -aOrientation.z );
    lPos.Multiply( lOrient );
    lOrient.SetRotation( gp_Ax1( gp_Pnt( 0.0, 0.0, 0.0 ),
        gp_Dir( 0.0, 1.0, 0.0 ) ), -aOrientation.y );
    lPos.Multiply( lOrient );
    lOrient.SetRotation( gp_Ax1( gp_Pnt( 0.0, 0.0, 0.0 ),
        gp_Dir( 1.0, 0.0, 0.0 ) ), -aOrientation.x );
    lPos.Multiply( lOrient );

    aLocation = TopLoc_Location( lPos );
    return true;
}
GEOMAlgo_FinderShapeOnQuad::GEOMAlgo_FinderShapeOnQuad(const gp_Pnt & theTopLeftPoint,
                                                       const gp_Pnt & theTopRigthPoint,
                                                       const gp_Pnt & theBottomLeftPoint,
                                                       const gp_Pnt & theBottomRigthPoint)
{
  myPoints.resize(6);
  myPoints[0] = theTopLeftPoint    ;
  myPoints[1] = theTopRigthPoint   ;
  myPoints[2] = theBottomRigthPoint;
  myPoints[3] = theBottomLeftPoint ;
  myPoints[4] = myPoints[0];
  myPoints[5] = myPoints[1];

  // Find plane normal defined by corner points, it will be used to define a plane
  // for each quadrangle side.
  myQuadNormal.SetCoord (0,0,0);
  for ( int i = 1; i <= 4; ++i )
    myQuadNormal += gp_Vec( myPoints[i], myPoints[i+1] ) ^ gp_Vec( myPoints[i], myPoints[i-1] );
  //std::cout<<std::endl<<" X Vec : "<<myQuadNormal.X()<<" "<<myQuadNormal.Y()<<" "<<myQuadNormal.Z()<<" "<<endl;

  if ( myQuadNormal.SquareMagnitude() <= DBL_MIN ) {
    myErrorStatus = 101;
    return;
  }

  // detect concave quadrangle sides
  myConcaveQuad = false;
  myConcaveSide.resize (4, false);
  for ( int i = 1; i <= 4; ++i ) {
    gp_Vec localQN = gp_Vec( myPoints[i], myPoints[i+1] ) ^ gp_Vec( myPoints[i], myPoints[i-1] );
    if ( myQuadNormal * localQN < 0 )
      myConcaveSide[i-1] = myConcaveSide[i] = myConcaveQuad = true;
  }

  // loop on quadrangle sides
  myPlanes.reserve( 4 );
  for ( int i = 0; i < 4; ++i )
  {
    // point1 -> point2 vector
    gp_Vec aSideVec( myPoints[ i ], myPoints[ i + 1 ]);
    //std::cout<<" Y Vec : "<<aSideVec.X()<<" "<<aSideVec.Y()<<" "<<aSideVec.Z()<<" "<<endl;

    // plane normal
    gp_Vec aSideNorm = aSideVec ^ myQuadNormal;
    if ( aSideNorm.SquareMagnitude() <= DBL_MIN )
      continue;
    //std::cout<<" Z Vec : "<<aSideNorm.X()<<" "<<aSideNorm.Y()<<" "<<aSideNorm.Z()<<" "<<endl;

    // make plane
    Handle(Geom_Plane) aPlane = new Geom_Plane( myPoints[ i ], aSideNorm );
    myPlanes.push_back( GeomAdaptor_Surface() );
    myPlanes.back().Load( aPlane );
  }
}
Пример #10
0
bool HLine::Intersects(const gp_Pnt &pnt)const
{
	gp_Lin this_line = GetLine();
	if(!intersect(pnt, this_line))return false;

	// check it lies between A and B
	gp_Vec v = this_line.Direction();
	double dpA = gp_Vec(A->m_p.XYZ()) * v;
	double dpB = gp_Vec(B->m_p.XYZ()) * v;
	double dp = gp_Vec(pnt.XYZ()) * v;
	return dp >= dpA - wxGetApp().m_geom_tol && dp <= dpB + wxGetApp().m_geom_tol;
}
Пример #11
0
bool CShape::GetExtents(double* extents, const double* orig, const double* xdir, const double* ydir, const double* zdir)
{
	gp_Pnt p_orig(0, 0, 0);
	if(orig)p_orig = gp_Pnt(orig[0], orig[1], orig[2]);
	gp_Vec v_x(1, 0, 0);
	if(xdir)v_x = gp_Vec(xdir[0], xdir[1], xdir[2]);
	gp_Vec v_y(0, 1, 0);
	if(ydir)v_y = gp_Vec(ydir[0], ydir[1], ydir[2]);
	gp_Vec v_z(0, 0, 1);
	if(zdir)v_z = gp_Vec(zdir[0], zdir[1], zdir[2]);

	BRepPrimAPI_MakeBox cuboid_plus_x(gp_Ax2(gp_Pnt(p_orig.XYZ() + 2000000 * v_x.XYZ() + (-1000000) * v_z.XYZ() + (-1000000) * v_y.XYZ()), v_x, v_y), 1000000, 1000000, 1000000);
	BRepPrimAPI_MakeBox cuboid_minus_x(gp_Ax2(gp_Pnt(p_orig.XYZ() + (-2000000) * v_x.XYZ() + (-1000000) * v_z.XYZ() + (-1000000) * v_y.XYZ()), -v_x, v_z), 1000000, 1000000, 1000000);
	BRepPrimAPI_MakeBox cuboid_plus_y(gp_Ax2(gp_Pnt(p_orig.XYZ() + 2000000 * v_y.XYZ() + (-1000000) * v_z.XYZ() + (-1000000) * v_x.XYZ()), v_y, v_z), 1000000, 1000000, 1000000);
	BRepPrimAPI_MakeBox cuboid_minus_y(gp_Ax2(gp_Pnt(p_orig.XYZ() + (-2000000) * v_y.XYZ() + (-1000000) * v_z.XYZ() + (-1000000) * v_x.XYZ()), -v_y, v_x), 1000000, 1000000, 1000000);
	BRepPrimAPI_MakeBox cuboid_plus_z(gp_Ax2(gp_Pnt(p_orig.XYZ() + 2000000 * v_z.XYZ() + (-1000000) * v_x.XYZ() + (-1000000) * v_y.XYZ()), v_z, v_x), 1000000, 1000000, 1000000);
	BRepPrimAPI_MakeBox cuboid_minus_z(gp_Ax2(gp_Pnt(p_orig.XYZ() + (-2000000) * v_z.XYZ() + (-1000000) * v_x.XYZ() + (-1000000) * v_y.XYZ()), -v_z, v_y), 1000000, 1000000, 1000000);

	gp_Vec v_orig(p_orig.XYZ());

	TopoDS_Solid shape[6] =
	{
		cuboid_minus_x,
		cuboid_minus_y,
		cuboid_minus_z,
		cuboid_plus_x,
		cuboid_plus_y,
		cuboid_plus_z
	};

	gp_Vec vector[6] =
	{
		v_x,
		v_y,
		v_z,
		v_x,
		v_y,
		v_z
	};

	for(int i = 0; i<6; i++){
		BRepExtrema_DistShapeShape extrema(m_shape, shape[i]);
		extrema.Perform();
		gp_Pnt p = extrema.PointOnShape1(1);
		gp_Vec v(p.XYZ());
		double dp = v * vector[i];
		double dp_o = v_orig * vector[i];
		extents[i] = dp - dp_o;
	}

	return true;
}
Пример #12
0
bool IfcGeom::Kernel::convert(const IfcSchema::IfcPolygonalBoundedHalfSpace* l, TopoDS_Shape& shape) {
	TopoDS_Shape halfspace;
	if ( ! IfcGeom::Kernel::convert((IfcSchema::IfcHalfSpaceSolid*)l,halfspace) ) return false;	
	TopoDS_Wire wire;
	if ( ! convert_wire(l->PolygonalBoundary(),wire) || ! wire.Closed() ) return false;	
	gp_Trsf trsf;
	convert(l->Position(),trsf);
	TopoDS_Shape prism = BRepPrimAPI_MakePrism(BRepBuilderAPI_MakeFace(wire),gp_Vec(0,0,200));
	gp_Trsf down; down.SetTranslation(gp_Vec(0,0,-100.0));
	prism.Move(trsf*down);
	shape = BRepAlgoAPI_Common(halfspace,prism);
	return true;
}
Пример #13
0
void LVPS_GM2Displacement::Calculate(LVPS_XYZNode* nodes)
{
	double x = (nodes[DisplacementNodeX.ID].S);
	double y = (nodes[DisplacementNodeY.ID].S);
	gp_Vec vec;
	vec = gp_Vec(1,0,0)*x;
	aTrsf.SetTranslation(vec);
	vec = gp_Vec(0,1,0)*y;
	gp_Trsf trsf;
	trsf.SetTranslation(vec);
	aTrsf=trsf*aTrsf;
	
};
Пример #14
0
gp_Vec CCPACSControlSurfaceDevice::getNormalOfControlSurfaceDevice()
{
    gp_Pnt point1 = _segment->GetPoint(0,0);
    gp_Pnt point2 = _segment->GetPoint(0,1);
    gp_Pnt point3 = _segment->GetPoint(1,0);

    gp_Vec dir1to2 = -(gp_Vec(point1.XYZ()) - gp_Vec(point2.XYZ()));
    gp_Vec dir1to3 = -(gp_Vec(point1.XYZ()) - gp_Vec(point3.XYZ()));

    gp_Vec nvV = dir1to2^dir1to3;
    nvV.Normalize();
    return nvV;
}
Пример #15
0
gp_Vec normalToFaceAtUV(const TopoDS_Face& face, double u, double v)
{
  BRepLProp_SLProps localSurfaceProps(1, 1e-6);
  localSurfaceProps.SetSurface(BRepAdaptor_Surface(face));
  localSurfaceProps.SetParameters(u, v);
  if (localSurfaceProps.IsNormalDefined()) {
    const gp_Dir& nc = localSurfaceProps.Normal();
    if (face.Orientation() == TopAbs_REVERSED)
      return gp_Vec(-nc.X(), -nc.Y(), -nc.Z());
    else
      return gp_Vec(nc.X(), nc.Y(), nc.Z());
  }
  return gp_Vec(0., 0., 1.);
  //return normalToSurfaceAtUV(BRep_Tool::Surface(face), u, v);
}
Пример #16
0
void GetGridBox(const CViewPoint *view_point, CBox &ext){
	gp_Pnt sp[4];
	double zval = 0.5;
	wxSize size = wxGetApp().m_current_viewport->GetViewportSize();
	sp[0] = gp_Pnt(0, 0, zval);
	sp[1] = gp_Pnt(size.GetWidth(), 0, zval);
	sp[2] = gp_Pnt(size.GetWidth(), size.GetHeight(), zval);
	sp[3] = gp_Pnt(0, size.GetHeight(), zval);
	gp_Vec vx, vy;
	view_point->GetTwoAxes(vx, vy, false, 0);
	gp_Pnt datum(0, 0, 0);
	gp_Trsf orimat = wxGetApp().GetDrawMatrix(false);
	datum.Transform(orimat);
	orimat = make_matrix(datum, vx, vy);
	gp_Pln plane(datum, gp_Vec(0, 0, 1).Transformed(orimat));
	{
		for(int i =0; i<4; i++){
			gp_Pnt p1 = view_point->glUnproject(sp[i]);
			sp[i].SetZ(0);
			gp_Pnt p2 = view_point->glUnproject(sp[i]);
			gp_Lin line = make_line(p1, p2);
			gp_Pnt pnt;
			if(intersect(line, plane, pnt))
			{
				ext.Insert(pnt.X(), pnt.Y(), pnt.Z());
			}
		}
	}
}
Пример #17
0
void occQt::testCommon()
{
    gp_Ax2 anAxis;
    anAxis.SetLocation(gp_Pnt(0.0, 110.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 aCommonShape = BRepAlgoAPI_Common(aTopoBox, aTopoSphere);

    gp_Trsf aTrsf;
    aTrsf.SetTranslation(gp_Vec(8.0, 0.0, 0.0));
    BRepBuilderAPI_Transform aTransform(aCommonShape, aTrsf);

    Handle_AIS_Shape anAisBox = new AIS_Shape(aTopoBox);
    Handle_AIS_Shape anAisSphere = new AIS_Shape(aTopoSphere);
    Handle_AIS_Shape anAisCommonShape = new AIS_Shape(aTransform.Shape());

    anAisBox->SetColor(Quantity_NOC_SPRINGGREEN);
    anAisSphere->SetColor(Quantity_NOC_STEELBLUE);
    anAisCommonShape->SetColor(Quantity_NOC_ROYALBLUE);

    mContext->Display(anAisBox);
    mContext->Display(anAisSphere);
    mContext->Display(anAisCommonShape);
}
//=======================================================================
//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;
}
Пример #19
0
void CCylinder::MakeTransformedShape(const gp_Trsf &mat)
{
	m_pos.Transform(mat);
	double scale = gp_Vec(1, 0, 0).Transformed(mat).Magnitude();
	m_radius = fabs(m_radius * scale);
	m_height = fabs(m_height * scale);
	m_shape = MakeCylinder(m_pos, m_radius, m_height);
}
Пример #20
0
void CTiglControlSurfaceHingeLine::buildHingeLine() const
{
    if (!_invalidated) {
        return;
    }
    
    if (!_segment || !_path || !_outerShape) {
        throw CTiglError("Null pointer in CTiglControlSurfaceHingeLine::buildHingeLine!", TIGL_NULL_POINTER);
    }
    
    // Calculate inner and outer HingePoint
    for ( int borderCounter = 0; borderCounter < 2; borderCounter++ ) {
        const CCPACSControlSurfaceDeviceOuterShapeBorder* border = NULL;
        double hingeXsi;
        if (borderCounter == 0) {
            border = &_outerShape->getOuterBorder();
            hingeXsi = _path->getOuterHingePoint().getXsi();
        }
        else {
            border = &_outerShape->getInnerBorder();
            hingeXsi = _path->getInnerHingePoint().getXsi();
        }

        double borderEtaLE = border->getEtaLE();
        double borderEtaTE = border->getEtaTE();
        double hingeEta = -1;

        // only calculate etaCoordinate if it´s not the same as the other one.
        if ( fabs(borderEtaLE - borderEtaTE) < 0.0001 ) {
            hingeEta = (borderEtaTE + borderEtaLE)/2;
        }
        else {
            double m = ( borderEtaLE - borderEtaTE )/(border->getXsiLE() - border->getXsiTE());
            hingeEta = m * (hingeXsi - border->getXsiLE()) + borderEtaLE;
        }

        double eta = 0.,xsi = 0.;
        CCPACSWingSegment* wsegment = _segment->GetSegmentEtaXsi(hingeEta,hingeXsi,eta,xsi);
        gp_Pnt hingeUpper = wsegment->GetUpperPoint(eta,xsi);
        gp_Pnt hingeLower = wsegment->GetLowerPoint(eta,xsi);

        if (borderCounter == 0) {
            double relHeight = _path->getOuterHingePoint().getRelHeight();
            gp_Vec upperToLower = (gp_Vec(hingeLower.XYZ()) - gp_Vec(hingeUpper.XYZ())).Multiplied(relHeight);
            _outerHingePoint = gp_Pnt(( gp_Vec(hingeUpper.XYZ()) + gp_Vec(upperToLower.XYZ() )).XYZ());
        }
        else {
            double relHeight = _path->getInnerHingePoint().getRelHeight();
            gp_Vec upperToLower = (gp_Vec(hingeLower.XYZ()) - gp_Vec(hingeUpper.XYZ())).Multiplied(relHeight);
            _innerHingePoint = gp_Pnt(( gp_Vec(hingeUpper.XYZ()) + gp_Vec(upperToLower.XYZ() )).XYZ());
        }
    }
    
    _invalidated = false;
}
Пример #21
0
void CCuboid::MakeTransformedShape(const gp_Trsf &mat)
{
	m_pos.Transform(mat);
	double scale = gp_Vec(1, 0, 0).Transformed(mat).Magnitude();
	m_x = fabs(m_x * scale);
	m_y = fabs(m_y * scale);
	m_z = fabs(m_z * scale);
	m_shape = BRepPrimAPI_MakeBox(m_pos, m_x, m_y, m_z).Shape();
}
Пример #22
0
void CCone::MakeTransformedShape(const gp_Trsf &mat)
{
	m_pos.Transform(mat);
	double scale = gp_Vec(1, 0, 0).Transformed(mat).Magnitude();
	m_r1 = fabs(m_r1 * scale);
	m_r2 = fabs(m_r2 * scale);
	m_height = fabs(m_height * scale);
	m_shape = BRepPrimAPI_MakeCone(m_pos, m_r1, m_r2, m_height).Shape();
}
void LVPS_GM2Displacement1Rotation::Calculate(LVPS_XYZNode* nodes)
{
	double xi = (nodes[DisplacementNodeX.ID].S);
	double yi = (nodes[DisplacementNodeY.ID].S);
	gp_Vec vec;
	vec = gp_Vec(1,0,0)*xi;
	aTrsf.SetTranslation(vec);
	vec = gp_Vec(0,1,0)*yi;
	gp_Trsf trsf, trsf1;
	trsf.SetTranslation(vec);
	aTrsf=trsf*aTrsf;
	
	Standard_Real X=x+nodes[DisplacementNodeX.ID].S;
	Standard_Real Y=y+nodes[DisplacementNodeY.ID].S;

	trsf1.SetRotation(gp_Ax1(gp_Pnt(X,Y,0),/*axisZ*/gp_Dir(0,0,1)),nodes[RotationNode.ID].S);

	aTrsf=trsf1*aTrsf;
	
};
Пример #24
0
TopoDS_Face buildEtaCutFace(const CTiglWingStructureReference& wsr, double eta)
{
    // NOTE: we have to determine the cut plane by using the 
    // GetMidplaneOrChordlinePoint methods for handling the case when the eta line
    // is extended because of an z-rotation of the outer or inner sections
    gp_Pnt startPnt = wsr.GetMidplaneOrChordlinePoint(eta, 0);
    gp_Pnt endPnt = wsr.GetMidplaneOrChordlinePoint(eta, 1);
    gp_Vec midplaneNormal = wsr.GetMidplaneNormal(eta);
    gp_Dir cutPlaneNormal = midplaneNormal.Crossed(gp_Vec(startPnt, endPnt));
    gp_Pln etaCutPlane = gp_Pln(startPnt, cutPlaneNormal);
    return BRepBuilderAPI_MakeFace(etaCutPlane);
}
Пример #25
0
void CPattern::GetMatrices(std::list<gp_Trsf> &matrices)
{
	gp_Trsf m2;
	gp_Trsf shift_m2;
	shift_m2.SetTranslationPart(gp_Vec(m_x_shift2, m_y_shift2, 0.0));
	gp_Trsf shift_m1;
	shift_m1.SetTranslationPart(gp_Vec(m_x_shift1, m_y_shift1, 0.0));

	for(int j =0; j<m_copies2; j++)
	{
		gp_Trsf m = m2;

		for(int i =0; i<m_copies1; i++)
		{
			matrices.push_back(m);
			m = m * shift_m1;
		}

		m2 = m2 * shift_m2;
	}
}
Пример #26
0
    Py::Object writeCameraFile(const Py::Tuple& args)
    {
        PyObject *Arg[4];
        const char *FileName;
        double vecs[4][3];
        if (!PyArg_ParseTuple(args.ptr(), "sO!O!O!O!",&FileName,&PyTuple_Type,
            &Arg[0],&PyTuple_Type, &Arg[1],&PyTuple_Type, &Arg[2],&PyTuple_Type, &Arg[3])) 
            throw Py::Exception();

        // go through the Tuple of Tuples
        for (int i=0;i<4;i++) {
            // check the right size of the Tuple of floats
            if (PyTuple_GET_SIZE(Arg[i]) != 3)
                throw Py::ValueError("Wrong parameter format, four Tuple of three floats needed!");

            // go through the Tuple of floats
            for (int l=0;l<3;l++) {
                PyObject* temp = PyTuple_GetItem(Arg[i],l);
                // check Type
                if (PyFloat_Check(temp))
                    vecs[i][l] = PyFloat_AsDouble(temp);
                else if (PyLong_Check(temp))
                    vecs[i][l] = (double) PyLong_AsLong(temp);
#if PY_MAJOR_VERSION < 3
                else if (PyInt_Check(temp))
                    vecs[i][l] = (double)  PyInt_AsLong(temp);
#endif
                else
                    throw Py::ValueError("Wrong parameter format, four Tuple of three floats needed!");
            }
        }

        // call the write method of PovTools....
        PovTools::writeCamera(FileName,CamDef(gp_Vec(vecs[0][0],vecs[0][1],vecs[0][2]),
                                              gp_Vec(vecs[1][0],vecs[1][1],vecs[1][2]),
                                              gp_Vec(vecs[2][0],vecs[2][1],vecs[2][2]),
                                              gp_Vec(vecs[3][0],vecs[3][1],vecs[3][2])));

        return Py::None();
    }
Пример #27
0
void occQt::makeExtrude()
{
    // prism a vertex result is an edge.
    TopoDS_Vertex aVertex = BRepBuilderAPI_MakeVertex(gp_Pnt(0.0, 60.0, 0.0));
    TopoDS_Shape aPrismVertex = BRepPrimAPI_MakePrism(aVertex, gp_Vec(0.0, 0.0, 5.0));
    Handle_AIS_Shape anAisPrismVertex = new AIS_Shape(aPrismVertex);

    // prism an edge result is a face.
    TopoDS_Edge anEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(5.0, 60.0, 0.0), gp_Pnt(10.0, 60.0, 0.0));
    TopoDS_Shape aPrismEdge = BRepPrimAPI_MakePrism(anEdge, gp_Vec(0.0, 0.0, 5.0));
    Handle_AIS_Shape anAisPrismEdge = new AIS_Shape(aPrismEdge);

    // prism a wire result is a shell.
    gp_Ax2 anAxis;
    anAxis.SetLocation(gp_Pnt(16.0, 60.0, 0.0));

    TopoDS_Edge aCircleEdge = BRepBuilderAPI_MakeEdge(gp_Circ(anAxis, 3.0));
    TopoDS_Wire aCircleWire = BRepBuilderAPI_MakeWire(aCircleEdge);
    TopoDS_Shape aPrismCircle = BRepPrimAPI_MakePrism(aCircleWire, gp_Vec(0.0, 0.0, 5.0));
    Handle_AIS_Shape anAisPrismCircle = new AIS_Shape(aPrismCircle);

    // prism a face or a shell result is a solid.
    anAxis.SetLocation(gp_Pnt(24.0, 60.0, 0.0));
    TopoDS_Edge aEllipseEdge = BRepBuilderAPI_MakeEdge(gp_Elips(anAxis, 3.0, 2.0));
    TopoDS_Wire aEllipseWire = BRepBuilderAPI_MakeWire(aEllipseEdge);
    TopoDS_Face aEllipseFace = BRepBuilderAPI_MakeFace(gp_Pln(gp::XOY()), aEllipseWire);
    TopoDS_Shape aPrismEllipse = BRepPrimAPI_MakePrism(aEllipseFace, gp_Vec(0.0, 0.0, 5.0));
    Handle_AIS_Shape anAisPrismEllipse = new AIS_Shape(aPrismEllipse);

    anAisPrismVertex->SetColor(Quantity_NOC_PAPAYAWHIP);
    anAisPrismEdge->SetColor(Quantity_NOC_PEACHPUFF);
    anAisPrismCircle->SetColor(Quantity_NOC_PERU);
    anAisPrismEllipse->SetColor(Quantity_NOC_PINK);

    mContext->Display(anAisPrismVertex);
    mContext->Display(anAisPrismEdge);
    mContext->Display(anAisPrismCircle);
    mContext->Display(anAisPrismEllipse);
}
Пример #28
0
  /*!
   * (Re)create the assembly object and its view as specified in
   * the XML representation.
   */
  void create ( void )
  {
    QDomNodeList memento_list = xml_doc_.elementsByTagName( lC::STR::MEMENTO );

    if ( memento_list.length() > 0 ) {
      DBURL url = memento_list.item(0).toElement().attribute( lC::STR::NAME );

      // First, we have to find the parent page and view for the subassembly.

      DBURL parent = url.parent();

      Space3D::Page* page =
	dynamic_cast<Space3D::Page*>( design_book_view_->model()->lookup( parent ));
      AssemblyView* assembly_view =
	dynamic_cast<AssemblyView*>( design_book_view_->lookup( parent ) );

      // Now, we can extract the XML representations for the subassembly
      // and its view
      QDomNodeList subassembly_list =
	xml_doc_.elementsByTagName( lC::STR::SUBASSEMBLY );

      if ( subassembly_list.length() > 0 ) {

	QDomNodeList subassembly_view_list =
	  xml_doc_.elementsByTagName( lC::STR::SUBASSEMBLY_VIEW );

	if ( subassembly_view_list.length() > 0 ) {
	  uint subassembly_id =
	    subassembly_list.item(0).toElement().attribute( lC::STR::ID ).toUInt();

	  Subassembly* subassembly =
	    new Subassembly( subassembly_id, subassembly_list.item(0).toElement(),
			     page );

	  SubassemblyView* subassembly_view =
	    new SubassemblyView( subassembly_view_list.item(0).
				 toElement(), assembly_view );
	  assembly_view->addFigureView( subassembly_view );

	  // Highly experimental...

	  // Move yourself a little bit just in case.
      if ( subassembly->constraints().getCount() == 0 )
	    subassembly->translate( gp_Vec( 20, 0, 0 ) );
	  
      if ( subassembly->constraints().getCount() < 3 )
	    assembly_view->editConstraints( subassembly_view );
	}
      }
    }
  }
Пример #29
0
bool HeeksObj::GetScaleAboutMatrix(double *m)
{
#ifdef HEEKSCAD
	// return the bottom left corner of the box
	CBox box;
	GetBox(box);
	if(!box.m_valid)return false;
	gp_Trsf mat;
	mat.SetTranslationPart(gp_Vec(box.m_x[0], box.m_x[1], box.m_x[2]));
	extract(mat, m);
	return true;
#else
	return false;
#endif
}
Пример #30
0
void get_clearance_points(gp_Pnt &p1_clearance, gp_Pnt &p2_clearance, double tooth_angle, double clearance)
{
	double incremental_angle = 0.5*M_PI/gear_for_point->m_num_teeth - middle_phi_and_angle.angle;
	double angle1 = tooth_angle - (inside_phi_and_angle.angle + incremental_angle);
	double angle2 = tooth_angle + (inside_phi_and_angle.angle + incremental_angle);
	gp_Pnt p1(cos(angle1) * inside_radius, sin(angle1) * inside_radius, 0);
	gp_Pnt p2(cos(angle2) * inside_radius, sin(angle2) * inside_radius, 0);

	gp_Vec v(p1, p2);
	gp_Vec v_in = gp_Vec(0, 0, 1) ^ v;
	v_in.Normalize();

	p1_clearance = gp_Pnt(p1.XYZ() + v_in.XYZ() * clearance);
	p2_clearance = gp_Pnt(p2.XYZ() + v_in.XYZ() * clearance);
}