mirror of
https://github.com/copyrighttxt/watrbx-game-engine.git
synced 2026-09-06 05:37:48 +00:00
GEEKING
This commit is contained in:
@@ -0,0 +1,244 @@
|
||||
#include "..//Core//sg.h"
|
||||
|
||||
sgC2DObject::sgC2DObject():sgCObject()
|
||||
{
|
||||
m_plane_normal.x = m_plane_normal.y = m_plane_normal.z = m_plane_D = 0.0;
|
||||
}
|
||||
|
||||
sgC2DObject::sgC2DObject(SG_OBJ_HANDLE objH):sgCObject(objH)
|
||||
{
|
||||
m_plane_normal.x = m_plane_normal.y = m_plane_normal.z = m_plane_D = 0.0;
|
||||
}
|
||||
|
||||
|
||||
sgCContour* sgC2DObject::GetEquidistantContour(sgFloat h1, sgFloat h2, bool toRound)
|
||||
{
|
||||
if (IsLinear() || !IsPlane(NULL,NULL))
|
||||
return NULL;
|
||||
|
||||
hOBJ eq_obj=NULL;
|
||||
if (!create_equ_path2(GetObjectHandle(this), NULL, h1, h2, false, &eq_obj))
|
||||
return NULL;
|
||||
if (eq_obj==NULL)
|
||||
return NULL;
|
||||
sgCObject* retO = ObjectFromHandle(eq_obj);
|
||||
if (retO->GetType()!=SG_OT_CONTOUR)
|
||||
{
|
||||
assert(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char* typeID = "{0000000000000-0000-0000-000000000007}";
|
||||
set_hobj_attr_value(id_TypeID, eq_obj, typeID);
|
||||
|
||||
return reinterpret_cast<sgCContour*>(retO);
|
||||
}
|
||||
|
||||
/*void sgC2DObject::GetEndPoints(SG_POINT* p1, SG_POINT* p2)
|
||||
{
|
||||
D_POINT tmpP;
|
||||
if (p1)
|
||||
{
|
||||
get_endpoint_on_path(GetObjectHandle(this),&tmpP,(OSTATUS)0);
|
||||
memcpy(p1,&tmpP,sizeof(SG_POINT));
|
||||
}
|
||||
if (p2)
|
||||
{
|
||||
get_endpoint_on_path(GetObjectHandle(this),&tmpP,ST_DIRECT);
|
||||
memcpy(p2,&tmpP,sizeof(SG_POINT));
|
||||
}
|
||||
}*/
|
||||
|
||||
sgC2DObject::SG_2D_OBJECT_ORIENT sgC2DObject::GetOrient(const SG_VECTOR& planeNormal) const
|
||||
{
|
||||
if (!IsClosed())
|
||||
return sgC2DObject::OO_ERROR;
|
||||
|
||||
D_PLANE pll;
|
||||
pll.d = 0.0;
|
||||
pll.v.x = planeNormal.x;pll.v.y = planeNormal.y;pll.v.z = planeNormal.z;
|
||||
switch(test_orient_path(GetObjectHandle(this), &pll))
|
||||
{
|
||||
case 1:
|
||||
return sgC2DObject::OO_ANTICLOCKWISE;
|
||||
case -1:
|
||||
return sgC2DObject::OO_CLOCKWISE;
|
||||
}
|
||||
return sgC2DObject::OO_ERROR;
|
||||
}
|
||||
|
||||
bool sgC2DObject::ChangeOrient()
|
||||
{
|
||||
lpOBJ obj = (lpOBJ)GetObjectHandle(this);
|
||||
obj->status ^= ST_DIRECT;
|
||||
return true;
|
||||
}
|
||||
|
||||
SG_POINT sgC2DObject::GetPointFromCoefficient(sgFloat coeff) const
|
||||
{
|
||||
D_POINT tmpP;
|
||||
SG_POINT resP = {0.0, 0.0, 0.0};
|
||||
if (coeff<eps_d)
|
||||
{
|
||||
get_endpoint_on_path(GetObjectHandle(this),&tmpP,(OSTATUS)0);
|
||||
memcpy(&resP,&tmpP,sizeof(SG_POINT));
|
||||
return resP;
|
||||
}
|
||||
if (coeff>(1.0-eps_d))
|
||||
{
|
||||
get_endpoint_on_path(GetObjectHandle(this),&tmpP,ST_DIRECT);
|
||||
memcpy(&resP,&tmpP,sizeof(SG_POINT));
|
||||
return resP;
|
||||
}
|
||||
if (!init_get_point_on_path(GetObjectHandle(this), NULL))
|
||||
{
|
||||
assert(0);
|
||||
return resP;
|
||||
}
|
||||
if (!get_point_on_path(coeff, &tmpP))
|
||||
{
|
||||
assert(0);
|
||||
return resP;
|
||||
}
|
||||
memcpy(&resP,&tmpP,sizeof(SG_POINT));
|
||||
term_get_point_on_path();
|
||||
return resP;
|
||||
}
|
||||
|
||||
bool sgC2DObject::IsObjectsOnOnePlane(const sgC2DObject& obj1,
|
||||
const sgC2DObject& obj2)
|
||||
{
|
||||
if (obj1.GetType()==SG_OT_LINE || obj2.GetType()==SG_OT_LINE)
|
||||
{
|
||||
if (obj1.GetType()==SG_OT_LINE && obj2.GetType()==SG_OT_LINE)
|
||||
{
|
||||
SG_POINT pp[4];
|
||||
sgCLine* f_l = reinterpret_cast<sgCLine*>(const_cast<sgC2DObject*>(&obj1));
|
||||
pp[0] = f_l->GetGeometry()->p1;
|
||||
pp[1] = f_l->GetGeometry()->p2;
|
||||
sgCLine* s_l = reinterpret_cast<sgCLine*>(const_cast<sgC2DObject*>(&obj2));
|
||||
pp[2] = s_l->GetGeometry()->p1;
|
||||
pp[3] = s_l->GetGeometry()->p2;
|
||||
if (!sgSpaceMath::IsPointsOnOneLine(pp[0],pp[1],pp[2]))
|
||||
{
|
||||
SG_VECTOR plNN;
|
||||
sgFloat plDD;
|
||||
sgSpaceMath::PlaneFromPoints(pp[0],pp[1],pp[2],plNN,plDD);
|
||||
if (sgSpaceMath::GetPlanePointDistance(pp[3],plNN,plDD)<eps_d)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else
|
||||
if (!sgSpaceMath::IsPointsOnOneLine(pp[0],pp[1],pp[3]))
|
||||
{
|
||||
SG_VECTOR plNN;
|
||||
sgFloat plDD;
|
||||
sgSpaceMath::PlaneFromPoints(pp[0],pp[1],pp[3],plNN,plDD);
|
||||
if (sgSpaceMath::GetPlanePointDistance(pp[2],plNN,plDD)<eps_d)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return true;
|
||||
}
|
||||
else
|
||||
if (obj1.GetType()==SG_OT_LINE && obj2.GetType()!=SG_OT_LINE)
|
||||
{
|
||||
SG_VECTOR plNN;
|
||||
sgFloat plDD;
|
||||
if (!obj2.IsPlane(&plNN,&plDD))
|
||||
return false;
|
||||
SG_POINT pp[2];
|
||||
sgCLine* f_l = reinterpret_cast<sgCLine*>(const_cast<sgC2DObject*>(&obj1));
|
||||
pp[0] = f_l->GetGeometry()->p1;
|
||||
pp[1] = f_l->GetGeometry()->p2;
|
||||
|
||||
if (sgSpaceMath::GetPlanePointDistance(pp[0],plNN,plDD)<eps_d &&
|
||||
sgSpaceMath::GetPlanePointDistance(pp[1],plNN,plDD)<eps_d)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else
|
||||
if (obj2.GetType()==SG_OT_LINE && obj1.GetType()!=SG_OT_LINE)
|
||||
{
|
||||
SG_VECTOR plNN;
|
||||
sgFloat plDD;
|
||||
if (!obj1.IsPlane(&plNN,&plDD))
|
||||
return false;
|
||||
SG_POINT pp[2];
|
||||
sgCLine* s_l = reinterpret_cast<sgCLine*>(const_cast<sgC2DObject*>(&obj2));
|
||||
pp[0] = s_l->GetGeometry()->p1;
|
||||
pp[1] = s_l->GetGeometry()->p2;
|
||||
|
||||
if (sgSpaceMath::GetPlanePointDistance(pp[0],plNN,plDD)<eps_d &&
|
||||
sgSpaceMath::GetPlanePointDistance(pp[1],plNN,plDD)<eps_d)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
D_POINT f_normal;
|
||||
D_POINT sec_normal;
|
||||
sgFloat f_D;
|
||||
sgFloat s_D;
|
||||
SG_VECTOR f_n;
|
||||
SG_VECTOR s_n;
|
||||
|
||||
if (!obj1.IsPlane(&f_n,&f_D))
|
||||
return false;
|
||||
if (!obj2.IsPlane(&s_n,&s_D))
|
||||
return false;
|
||||
memcpy(&f_normal,&f_n,sizeof(D_POINT));
|
||||
memcpy(&sec_normal,&s_n,sizeof(D_POINT));
|
||||
|
||||
if (!((dpoint_eq(&f_normal,&sec_normal,eps_n) &&
|
||||
fabs(f_D - s_D) < eps_d) ||
|
||||
(dpoint_eq(&f_normal,dpoint_inv(&sec_normal,&sec_normal),eps_n) &&
|
||||
fabs(f_D + s_D) < eps_d)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool sgC2DObject::IsObjectsIntersecting(const sgC2DObject& obj1,
|
||||
const sgC2DObject& obj2)
|
||||
{
|
||||
if (!IsObjectsOnOnePlane(obj1,obj2))
|
||||
return false;
|
||||
|
||||
OSCAN_COD scc = test_self_cross_path(GetObjectHandle(&obj1), GetObjectHandle(&obj2));
|
||||
if (scc==OSTRUE)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool sgC2DObject::IsFirstObjectInsideSecondObject(const sgC2DObject& obj1,
|
||||
const sgC2DObject& obj2)
|
||||
{
|
||||
if (!IsObjectsOnOnePlane(obj1,obj2))
|
||||
return false;
|
||||
|
||||
D_PLANE pll;
|
||||
SG_VECTOR f_n;
|
||||
|
||||
if (!obj1.IsPlane(&f_n,&pll.d))
|
||||
return false;
|
||||
|
||||
memcpy(&pll.v,&f_n,sizeof(D_POINT));
|
||||
|
||||
short scc = test_inside_path(GetObjectHandle(&obj1), GetObjectHandle(&obj2),&pll);
|
||||
if (scc==1)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,556 @@
|
||||
#include "..//Core//sg.h"
|
||||
|
||||
// a = new SG_POINT[]. delete[] ;
|
||||
//static SG_POINT* CalculateArcPoints(SG_ARC* arc, int& pnts_count);
|
||||
|
||||
|
||||
static SG_POINT arc_points_buffer[NUM_SEGMENTS+1];
|
||||
|
||||
static SG_POINT* GetPointsFromArcGeo(const SG_ARC* arc, int& pnts_count)
|
||||
{
|
||||
D_POINT p1_2D;
|
||||
D_POINT p2_2D;
|
||||
D_POINT vb, ve, vc;
|
||||
D_POINT p1_3D;
|
||||
D_POINT p2_3D;
|
||||
|
||||
short n;
|
||||
sgFloat dx, dy, dd, sp, cp;
|
||||
MATR mFrom2DTo3D;
|
||||
MATR mFrom3DTo2D;
|
||||
|
||||
lpGEO_ARC arcData = (lpGEO_ARC)arc;
|
||||
|
||||
o_hcunit(mFrom3DTo2D);
|
||||
o_tdtran(mFrom3DTo2D, dpoint_inv(&arcData->vc, &vc));
|
||||
o_hcrot1(mFrom3DTo2D, &arcData->n);
|
||||
|
||||
SG_POINT drP1,drP2;
|
||||
|
||||
o_minv(mFrom3DTo2D,mFrom2DTo3D);
|
||||
|
||||
o_hcncrd(mFrom3DTo2D, &arcData->vb, &vb);
|
||||
o_hcncrd(mFrom3DTo2D, &arcData->ve, &ve);
|
||||
o_hcncrd(mFrom3DTo2D, &arcData->vc, &vc);
|
||||
|
||||
n = (short)(NUM_SEGMENTS*(fabs(arcData->angle)/(2*M_PI)));
|
||||
if(n < MIN_NUM_SEGMENTS) n = MIN_NUM_SEGMENTS;
|
||||
dd = arcData->angle/n;
|
||||
|
||||
pnts_count = n+1;
|
||||
memset(arc_points_buffer,0,sizeof(SG_POINT)*(NUM_SEGMENTS+1));
|
||||
|
||||
|
||||
sp = sin(dd);
|
||||
cp = cos(dd);
|
||||
dx = vb.x - vc.x;
|
||||
dy = vb.y - vc.y;
|
||||
dpoint_copy( &p1_2D, &vb);
|
||||
o_hcncrd(mFrom2DTo3D, &p1_2D, &p1_3D);
|
||||
int i=0;
|
||||
while(--n){
|
||||
dd = dx;
|
||||
dx = dx*cp - dy*sp;
|
||||
dy = dd*sp + dy*cp;
|
||||
p2_2D.x = vc.x + dx;
|
||||
p2_2D.y = vc.y + dy;
|
||||
p2_2D.z = 0.;
|
||||
o_hcncrd(mFrom2DTo3D, &p2_2D, &p2_3D);
|
||||
drP1.x = p1_3D.x; drP1.y = p1_3D.y; drP1.z = p1_3D.z;
|
||||
drP2.x = p2_3D.x; drP2.y = p2_3D.y; drP2.z = p2_3D.z;
|
||||
arc_points_buffer[i++] = drP1;
|
||||
dpoint_copy(&p1_2D, &p2_2D);
|
||||
dpoint_copy(&p1_3D, &p2_3D);
|
||||
}
|
||||
arc_points_buffer[i++] = drP2;
|
||||
arc_points_buffer[i].x = arcData->ve.x;
|
||||
arc_points_buffer[i].y = arcData->ve.y;
|
||||
arc_points_buffer[i].z = arcData->ve.z;
|
||||
|
||||
return arc_points_buffer;
|
||||
}
|
||||
|
||||
|
||||
bool SG_ARC::FromThreePoints(const SG_POINT& begP,
|
||||
const SG_POINT& endP,
|
||||
const SG_POINT& midP,
|
||||
bool invert)// ,
|
||||
{
|
||||
radius = 0.0;
|
||||
normal.x = normal.y = normal.z = 0.0;
|
||||
center.x = center.y = center.z = 0.0;
|
||||
begin.x = begin.y = begin.z = 0.0;
|
||||
end.x = end.y = end.z = 0.0;
|
||||
begin_angle = angle =0.0;
|
||||
|
||||
sgFloat tmpD;
|
||||
SG_VECTOR tmpVec;
|
||||
if (!sgSpaceMath::PlaneFromPoints(begP,endP,midP,tmpVec,tmpD))
|
||||
{
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_CONFLICT_BEETWEEN_ARGS;
|
||||
return false;
|
||||
}
|
||||
if (!sgSpaceMath::NormalVector(tmpVec))
|
||||
{
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_CONFLICT_BEETWEEN_ARGS;
|
||||
return false;
|
||||
}
|
||||
|
||||
MATR mFrom2DTo3D;
|
||||
MATR mFrom3DTo2D;
|
||||
|
||||
o_hcunit(mFrom3DTo2D);
|
||||
lpD_POINT tmpP = reinterpret_cast<lpD_POINT>(&tmpVec);
|
||||
o_hcrot1(mFrom3DTo2D, tmpP);
|
||||
o_minv(mFrom3DTo2D,mFrom2DTo3D);
|
||||
|
||||
D_POINT p_2D[3];
|
||||
// , ,
|
||||
p_2D[0].x = begP.x;p_2D[0].y = begP.y;p_2D[0].z = begP.z;
|
||||
o_hcncrd(mFrom3DTo2D, &p_2D[0], &p_2D[0]);
|
||||
p_2D[1].x = endP.x;p_2D[1].y = endP.y;p_2D[1].z = endP.z;
|
||||
o_hcncrd(mFrom3DTo2D, &p_2D[1], &p_2D[1]);
|
||||
p_2D[2].x = midP.x;p_2D[2].y = midP.y;p_2D[2].z = midP.z;
|
||||
o_hcncrd(mFrom3DTo2D, &p_2D[2], &p_2D[2]);
|
||||
|
||||
GEO_ARC pArc;
|
||||
memcpy(&pArc, this, sizeof(SG_ARC));
|
||||
if (!arc_p_p_p(0,1,2,p_2D ,NULL,0,invert,&pArc))
|
||||
{
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_CONFLICT_BEETWEEN_ARGS;
|
||||
return false;
|
||||
}
|
||||
|
||||
pArc.n.x = tmpVec.x; pArc.n.y = tmpVec.y; pArc.n.z = tmpVec.z;
|
||||
|
||||
o_hcncrd(mFrom2DTo3D,&pArc.vb,&pArc.vb);
|
||||
o_hcncrd(mFrom2DTo3D,&pArc.ve,&pArc.ve);
|
||||
pArc.vc.z = p_2D[0].z;
|
||||
o_hcncrd(mFrom2DTo3D,&pArc.vc,&pArc.vc);
|
||||
|
||||
radius = pArc.r;
|
||||
normal.x = pArc.n.x;
|
||||
normal.y = pArc.n.y;
|
||||
normal.z = pArc.n.z;
|
||||
center.x = pArc.vc.x;
|
||||
center.y = pArc.vc.y;
|
||||
center.z = pArc.vc.z;
|
||||
begin.x = pArc.vb.x;
|
||||
begin.y = pArc.vb.y;
|
||||
begin.z = pArc.vb.z;
|
||||
end.x = pArc.ve.x;
|
||||
end.y = pArc.ve.y;
|
||||
end.z = pArc.ve.z;
|
||||
begin_angle = pArc.ab;
|
||||
angle = pArc.angle;
|
||||
|
||||
global_sg_error = SG_ER_SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SG_ARC::FromCenterBeginEnd(const SG_POINT& cenP,
|
||||
const SG_POINT& begP,
|
||||
const SG_POINT& endP,
|
||||
bool invert)// ,
|
||||
{
|
||||
radius = 0.0;
|
||||
normal.x = normal.y = normal.z = 0.0;
|
||||
center.x = center.y = center.z = 0.0;
|
||||
begin.x = begin.y = begin.z = 0.0;
|
||||
end.x = end.y = end.z = 0.0;
|
||||
begin_angle = angle =0.0;
|
||||
|
||||
sgFloat tmpD;
|
||||
SG_VECTOR tmpVec;
|
||||
if (!sgSpaceMath::PlaneFromPoints(begP,endP,cenP,tmpVec,tmpD))
|
||||
{
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_CONFLICT_BEETWEEN_ARGS;
|
||||
return false;
|
||||
}
|
||||
if (!sgSpaceMath::NormalVector(tmpVec))
|
||||
{
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_CONFLICT_BEETWEEN_ARGS;
|
||||
return false;
|
||||
}
|
||||
|
||||
MATR mFrom2DTo3D;
|
||||
MATR mFrom3DTo2D;
|
||||
|
||||
o_hcunit(mFrom3DTo2D);
|
||||
lpD_POINT tmpP = reinterpret_cast<lpD_POINT>(&tmpVec);
|
||||
o_hcrot1(mFrom3DTo2D, tmpP);
|
||||
o_minv(mFrom3DTo2D,mFrom2DTo3D);
|
||||
|
||||
D_POINT p_2D[3];
|
||||
// , ,
|
||||
p_2D[0].x = cenP.x;p_2D[0].y = cenP.y;p_2D[0].z = cenP.z;
|
||||
o_hcncrd(mFrom3DTo2D, &p_2D[0], &p_2D[0]);
|
||||
p_2D[1].x = begP.x;p_2D[1].y = begP.y;p_2D[1].z = begP.z;
|
||||
o_hcncrd(mFrom3DTo2D, &p_2D[1], &p_2D[1]);
|
||||
p_2D[2].x = endP.x;p_2D[2].y = endP.y;p_2D[2].z = endP.z;
|
||||
o_hcncrd(mFrom3DTo2D, &p_2D[2], &p_2D[2]);
|
||||
|
||||
GEO_ARC pArc;
|
||||
memcpy(&pArc, this, sizeof(SG_ARC));
|
||||
|
||||
if (!arc_b_e_c(&p_2D[1],&p_2D[2],&p_2D[0],FALSE,FALSE,invert,&pArc))
|
||||
{
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_CONFLICT_BEETWEEN_ARGS;
|
||||
return false;
|
||||
}
|
||||
|
||||
pArc.n.x = tmpVec.x; pArc.n.y = tmpVec.y; pArc.n.z = tmpVec.z;
|
||||
|
||||
o_hcncrd(mFrom2DTo3D,&pArc.vb,&pArc.vb);
|
||||
o_hcncrd(mFrom2DTo3D,&pArc.ve,&pArc.ve);
|
||||
pArc.vc.z = p_2D[0].z;
|
||||
o_hcncrd(mFrom2DTo3D,&pArc.vc,&pArc.vc);
|
||||
|
||||
radius = pArc.r;
|
||||
normal.x = pArc.n.x;
|
||||
normal.y = pArc.n.y;
|
||||
normal.z = pArc.n.z;
|
||||
center.x = pArc.vc.x;
|
||||
center.y = pArc.vc.y;
|
||||
center.z = pArc.vc.z;
|
||||
begin.x = pArc.vb.x;
|
||||
begin.y = pArc.vb.y;
|
||||
begin.z = pArc.vb.z;
|
||||
end.x = pArc.ve.x;
|
||||
end.y = pArc.ve.y;
|
||||
end.z = pArc.ve.z;
|
||||
begin_angle = pArc.ab;
|
||||
angle = pArc.angle;
|
||||
|
||||
global_sg_error = SG_ER_SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SG_ARC::FromBeginEndNormalRadius(const SG_POINT& begP,
|
||||
const SG_POINT& endP,
|
||||
const SG_VECTOR& nrmlV,
|
||||
sgFloat rad,
|
||||
bool invert)// ,
|
||||
{
|
||||
radius = 0.0;
|
||||
normal.x = normal.y = normal.z = 0.0;
|
||||
center.x = center.y = center.z = 0.0;
|
||||
begin.x = begin.y = begin.z = 0.0;
|
||||
end.x = end.y = end.z = 0.0;
|
||||
begin_angle = angle =0.0;
|
||||
|
||||
// , , ,
|
||||
D_POINT pnts[2];
|
||||
|
||||
pnts[0].x = begP.x;
|
||||
pnts[0].y = begP.y;
|
||||
pnts[0].z = begP.z;
|
||||
pnts[1].x = endP.x;
|
||||
pnts[1].y = endP.y;
|
||||
pnts[1].z = endP.z;
|
||||
//
|
||||
D_POINT nrml;
|
||||
nrml.x = nrmlV.x;
|
||||
nrml.y = nrmlV.y;
|
||||
nrml.z = nrmlV.z;
|
||||
|
||||
MATR matrix;
|
||||
o_hcunit(matrix);
|
||||
o_hcrot1(matrix,&nrml);
|
||||
o_hcncrd(matrix,&pnts[0],&pnts[0]);
|
||||
o_hcncrd(matrix,&pnts[1],&pnts[1]);
|
||||
GEO_ARC pArc;
|
||||
memcpy(&pArc, this, sizeof(SG_ARC));
|
||||
if (!arc_b_e_r(&pnts[0],&pnts[1],rad,invert,&pArc))
|
||||
{
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_CONFLICT_BEETWEEN_ARGS;
|
||||
return false;
|
||||
}
|
||||
dpoint_copy(&pArc.n,&nrml);
|
||||
|
||||
o_minv(matrix,matrix);
|
||||
|
||||
o_hcncrd(matrix,&pArc.vb,&pArc.vb);
|
||||
o_hcncrd(matrix,&pArc.ve,&pArc.ve);
|
||||
o_hcncrd(matrix,&pArc.vc,&pArc.vc);
|
||||
|
||||
radius = pArc.r;
|
||||
normal.x = pArc.n.x;
|
||||
normal.y = pArc.n.y;
|
||||
normal.z = pArc.n.z;
|
||||
center.x = pArc.vc.x;
|
||||
center.y = pArc.vc.y;
|
||||
center.z = pArc.vc.z;
|
||||
begin.x = pArc.vb.x;
|
||||
begin.y = pArc.vb.y;
|
||||
begin.z = pArc.vb.z;
|
||||
end.x = pArc.ve.x;
|
||||
end.y = pArc.ve.y;
|
||||
end.z = pArc.ve.z;
|
||||
begin_angle = pArc.ab;
|
||||
angle = pArc.angle;
|
||||
|
||||
global_sg_error =SG_ER_SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SG_ARC::FromCenterBeginNormalAngle(const SG_POINT& cenP,
|
||||
const SG_POINT& begP,
|
||||
const SG_VECTOR& nrmlV,
|
||||
sgFloat ang)// ,
|
||||
{
|
||||
radius = 0.0;
|
||||
normal.x = normal.y = normal.z = 0.0;
|
||||
center.x = center.y = center.z = 0.0;
|
||||
begin.x = begin.y = begin.z = 0.0;
|
||||
end.x = end.y = end.z = 0.0;
|
||||
begin_angle = angle =0.0;
|
||||
|
||||
// , , ,
|
||||
D_POINT pnts[2];
|
||||
|
||||
pnts[0].x = cenP.x;
|
||||
pnts[0].y = cenP.y;
|
||||
pnts[0].z = cenP.z;
|
||||
pnts[1].x = begP.x;
|
||||
pnts[1].y = begP.y;
|
||||
pnts[1].z = begP.z;
|
||||
//
|
||||
D_POINT nrml;
|
||||
nrml.x = nrmlV.x;
|
||||
nrml.y = nrmlV.y;
|
||||
nrml.z = nrmlV.z;
|
||||
|
||||
MATR matrix;
|
||||
MATR matrix_inv;
|
||||
o_hcunit(matrix);
|
||||
o_hcrot1(matrix,&nrml);
|
||||
o_hcncrd(matrix,&pnts[0],&pnts[0]);
|
||||
o_hcncrd(matrix,&pnts[1],&pnts[1]);
|
||||
GEO_ARC pArc;
|
||||
memcpy(&pArc, this, sizeof(SG_ARC));
|
||||
if (!arc_b_c_a(&pnts[1],&pnts[0],ang,&pArc))
|
||||
{
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_CONFLICT_BEETWEEN_ARGS;
|
||||
return false;
|
||||
}
|
||||
dpoint_copy(&pArc.n,&nrml);
|
||||
|
||||
o_minv(matrix,matrix_inv);
|
||||
|
||||
o_hcncrd(matrix_inv,&pArc.vb,&pArc.vb);
|
||||
pArc.ve.z = pArc.vc.z;
|
||||
o_hcncrd(matrix_inv,&pArc.ve,&pArc.ve);
|
||||
o_hcncrd(matrix_inv,&pArc.vc,&pArc.vc);
|
||||
|
||||
radius = pArc.r;
|
||||
normal.x = pArc.n.x;
|
||||
normal.y = pArc.n.y;
|
||||
normal.z = pArc.n.z;
|
||||
center.x = pArc.vc.x;
|
||||
center.y = pArc.vc.y;
|
||||
center.z = pArc.vc.z;
|
||||
begin.x = pArc.vb.x;
|
||||
begin.y = pArc.vb.y;
|
||||
begin.z = pArc.vb.z;
|
||||
end.x = pArc.ve.x;
|
||||
end.y = pArc.ve.y;
|
||||
end.z = pArc.ve.z;
|
||||
begin_angle = pArc.ab;
|
||||
angle = pArc.angle;
|
||||
|
||||
global_sg_error = SG_ER_SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SG_ARC::FromBeginEndNormalAngle(const SG_POINT& begP,
|
||||
const SG_POINT& endP,
|
||||
const SG_VECTOR& nrmlV,
|
||||
sgFloat ang)// ,
|
||||
{
|
||||
radius = 0.0;
|
||||
normal.x = normal.y = normal.z = 0.0;
|
||||
center.x = center.y = center.z = 0.0;
|
||||
begin.x = begin.y = begin.z = 0.0;
|
||||
end.x = end.y = end.z = 0.0;
|
||||
begin_angle = angle =0.0;
|
||||
|
||||
// , , ,
|
||||
D_POINT pnts[2];
|
||||
pnts[0].x = begP.x;
|
||||
pnts[0].y = begP.y;
|
||||
pnts[0].z = begP.z;
|
||||
pnts[1].x = endP.x;
|
||||
pnts[1].y = endP.y;
|
||||
pnts[1].z = endP.z;
|
||||
//
|
||||
D_POINT nrml;
|
||||
nrml.x = nrmlV.x;
|
||||
nrml.y = nrmlV.y;
|
||||
nrml.z = nrmlV.z;
|
||||
|
||||
MATR matrix;
|
||||
o_hcunit(matrix);
|
||||
o_hcrot1(matrix,&nrml);
|
||||
o_hcncrd(matrix,&pnts[0],&pnts[0]);
|
||||
o_hcncrd(matrix,&pnts[1],&pnts[1]);
|
||||
GEO_ARC pArc;
|
||||
memcpy(&pArc, this, sizeof(SG_ARC));
|
||||
if (!arc_b_e_a(&pnts[0],&pnts[1],ang,&pArc))
|
||||
{
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_CONFLICT_BEETWEEN_ARGS;
|
||||
return false;
|
||||
}
|
||||
dpoint_copy(&pArc.n,&nrml);
|
||||
|
||||
o_minv(matrix,matrix);
|
||||
|
||||
o_hcncrd(matrix,&pArc.vb,&pArc.vb);
|
||||
o_hcncrd(matrix,&pArc.ve,&pArc.ve);
|
||||
o_hcncrd(matrix,&pArc.vc,&pArc.vc);
|
||||
|
||||
radius = pArc.r;
|
||||
normal.x = pArc.n.x;
|
||||
normal.y = pArc.n.y;
|
||||
normal.z = pArc.n.z;
|
||||
center.x = pArc.vc.x;
|
||||
center.y = pArc.vc.y;
|
||||
center.z = pArc.vc.z;
|
||||
begin.x = pArc.vb.x;
|
||||
begin.y = pArc.vb.y;
|
||||
begin.z = pArc.vb.z;
|
||||
end.x = pArc.ve.x;
|
||||
end.y = pArc.ve.y;
|
||||
end.z = pArc.ve.z;
|
||||
begin_angle = pArc.ab;
|
||||
angle = pArc.angle;
|
||||
|
||||
global_sg_error = SG_ER_SUCCESS;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SG_ARC::Draw(SG_DRAW_LINE_FUNC line_func) const
|
||||
{
|
||||
if (line_func==NULL)
|
||||
{
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_NULL_POINTER;
|
||||
return false;
|
||||
}
|
||||
int pcnt=0;
|
||||
SG_POINT* pnts=NULL;
|
||||
pnts = GetPointsFromArcGeo(this,pcnt);
|
||||
for (int i=0;i<pcnt-1;i++)
|
||||
line_func(pnts+i, pnts+i+1);
|
||||
global_sg_error = SG_ER_SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
sgCArc::sgCArc():sgC2DObject()
|
||||
, m_points(NULL)
|
||||
, m_points_count(0)
|
||||
{
|
||||
}
|
||||
|
||||
sgCArc::sgCArc(SG_OBJ_HANDLE objH):sgC2DObject(objH)
|
||||
, m_points(NULL)
|
||||
, m_points_count(0)
|
||||
{
|
||||
char* typeID = "{0000000000000-0000-0000-000000000004}";
|
||||
set_hobj_attr_value(id_TypeID, objH, typeID);
|
||||
|
||||
m_points_count = NUM_SEGMENTS+1;
|
||||
m_points = new SG_POINT[m_points_count];
|
||||
|
||||
SG_ARC* arG = const_cast<SG_ARC*>(GetGeometry());
|
||||
memcpy(m_points,
|
||||
GetPointsFromArcGeo(arG,m_points_count),
|
||||
sizeof(SG_POINT)*m_points_count);
|
||||
memcpy(&m_plane_normal,&(arG->normal),sizeof(SG_VECTOR));
|
||||
sgSpaceMath::PlaneFromNormalAndPoint(arG->center,m_plane_normal,m_plane_D);
|
||||
|
||||
PostCreate();
|
||||
}
|
||||
|
||||
|
||||
bool sgCArc::ApplyTempMatrix()
|
||||
{
|
||||
if (!sgCObject::ApplyTempMatrix())
|
||||
return false;
|
||||
|
||||
SG_ARC* arG = const_cast<SG_ARC*>(GetGeometry());
|
||||
memcpy(m_points,
|
||||
GetPointsFromArcGeo(arG,m_points_count),
|
||||
sizeof(SG_POINT)*m_points_count);
|
||||
memcpy(&m_plane_normal,&(arG->normal),sizeof(SG_VECTOR));
|
||||
sgSpaceMath::PlaneFromNormalAndPoint(arG->center,m_plane_normal,m_plane_D);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
sgCArc::~sgCArc()
|
||||
{
|
||||
if (m_points)
|
||||
{
|
||||
delete[] m_points;
|
||||
m_points = NULL;
|
||||
m_points_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
sgCArc* sgCArc::Create(const SG_ARC& arcG)
|
||||
{
|
||||
sgCArc* newA=new sgCArc;
|
||||
global_sg_error = SG_ER_SUCCESS;
|
||||
SetObjectHandle(newA, create_simple_obj_loc(OARC, const_cast<SG_ARC*>(&arcG)));
|
||||
((lpOBJ)(GetObjectHandle(newA)))->extendedClass = newA;
|
||||
|
||||
char* typeID = "{0000000000000-0000-0000-000000000004}";
|
||||
set_hobj_attr_value(id_TypeID, GetObjectHandle(newA), typeID);
|
||||
|
||||
newA->m_points_count = NUM_SEGMENTS+1;
|
||||
newA->m_points = new SG_POINT[newA->m_points_count];
|
||||
SG_ARC* arG = const_cast<SG_ARC*>(newA->GetGeometry());
|
||||
memcpy(newA->m_points,
|
||||
GetPointsFromArcGeo(arG,newA->m_points_count),
|
||||
sizeof(SG_POINT)*newA->m_points_count);
|
||||
|
||||
memcpy(&(newA->m_plane_normal),&(arG->normal),sizeof(SG_VECTOR));
|
||||
sgSpaceMath::PlaneFromNormalAndPoint(arG->center,
|
||||
newA->m_plane_normal,newA->m_plane_D);
|
||||
|
||||
|
||||
newA->PostCreate();
|
||||
|
||||
return newA;
|
||||
}
|
||||
|
||||
const SG_ARC* sgCArc::GetGeometry() const
|
||||
{
|
||||
lpOBJ pobj = (lpOBJ)(GetObjectHandle(this));
|
||||
return static_cast<SG_ARC*>((void*)(pobj->geo_data));
|
||||
}
|
||||
|
||||
int sgCArc::GetPointsCount() const
|
||||
{
|
||||
return m_points_count;
|
||||
}
|
||||
|
||||
const SG_POINT* sgCArc::GetPoints() const
|
||||
{
|
||||
return m_points;
|
||||
}
|
||||
|
||||
bool sgCArc::IsClosed() const {return false;}
|
||||
bool sgCArc::IsPlane(SG_VECTOR* plN,sgFloat* plD) const
|
||||
{
|
||||
if (plN)
|
||||
*plN = m_plane_normal;
|
||||
if (plD)
|
||||
*plD = m_plane_D;
|
||||
return true;
|
||||
}
|
||||
bool sgCArc::IsLinear() const {return false;}
|
||||
bool sgCArc::IsSelfIntersecting() const {return false;}
|
||||
|
||||
@@ -0,0 +1,213 @@
|
||||
#include "..//CORE//sg.h"
|
||||
|
||||
sgCGroup* sgBoolean::Intersection(const sgC3DObject& aOb,const sgC3DObject& bOb)
|
||||
{
|
||||
sgCGroup* retVal=NULL;
|
||||
|
||||
LISTH resList;
|
||||
init_listh(&resList);
|
||||
|
||||
hOBJ reservObj = NULL;
|
||||
|
||||
if (boolean_operation(GetObjectHandle(&aOb), GetObjectHandle(&bOb),INTER,&resList)!=OSTRUE)
|
||||
{
|
||||
//assert(0);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
if (resList.num<1)
|
||||
return retVal;
|
||||
|
||||
sgCObject** objcts = (sgCObject**)malloc(sizeof(sgCObject*)*resList.num);
|
||||
hOBJ list_elem = resList.hhead;
|
||||
int i=0;
|
||||
while (list_elem)
|
||||
{
|
||||
char* typeID = "{0000000000000-0000-0000-000000000000}";
|
||||
set_hobj_attr_value(id_TypeID, list_elem, typeID);
|
||||
objcts[i++] = ObjectFromHandle(list_elem);
|
||||
get_next_item(list_elem,&list_elem);
|
||||
}
|
||||
|
||||
retVal = sgCGroup::CreateGroup(objcts,resList.num);
|
||||
|
||||
if (reservObj)
|
||||
{
|
||||
o_free(reservObj,NULL);
|
||||
}
|
||||
|
||||
free(objcts);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
sgCGroup* sgBoolean::Union(const sgC3DObject& aOb,const sgC3DObject& bOb, int& errcode)
|
||||
{
|
||||
sgCGroup* retVal=NULL;
|
||||
|
||||
LISTH resList;
|
||||
init_listh(&resList);
|
||||
|
||||
hOBJ reservObj = NULL;
|
||||
|
||||
errcode = boolean_operation(GetObjectHandle(&aOb), GetObjectHandle(&bOb),UNION,&resList);
|
||||
if (errcode!=OSTRUE)
|
||||
{
|
||||
//assert(0);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
if (resList.num<1)
|
||||
return retVal;
|
||||
|
||||
sgCObject** objcts = (sgCObject**)malloc(sizeof(sgCObject*)*resList.num);
|
||||
hOBJ list_elem = resList.hhead;
|
||||
int i=0;
|
||||
while (list_elem)
|
||||
{
|
||||
char* typeID = "{0000000000000-0000-0000-000000000000}";
|
||||
set_hobj_attr_value(id_TypeID, list_elem, typeID);
|
||||
objcts[i++] = ObjectFromHandle(list_elem);
|
||||
get_next_item(list_elem,&list_elem);
|
||||
}
|
||||
|
||||
retVal = sgCGroup::CreateGroup(objcts,resList.num);
|
||||
|
||||
if (reservObj)
|
||||
{
|
||||
o_free(reservObj,NULL);
|
||||
}
|
||||
|
||||
free(objcts);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
sgCGroup* sgBoolean::Sub(const sgC3DObject& aOb,const sgC3DObject& bOb, int& errcode)
|
||||
{
|
||||
sgCGroup* retVal=NULL;
|
||||
|
||||
LISTH resList;
|
||||
init_listh(&resList);
|
||||
|
||||
hOBJ reservObj = NULL;
|
||||
|
||||
errcode = boolean_operation(GetObjectHandle(&aOb), GetObjectHandle(&bOb),SUB,&resList);
|
||||
if (errcode!=OSTRUE)
|
||||
{
|
||||
//assert(0);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
if (resList.num<1)
|
||||
return retVal;
|
||||
|
||||
sgCObject** objcts = (sgCObject**)malloc(sizeof(sgCObject*)*resList.num);
|
||||
hOBJ list_elem = resList.hhead;
|
||||
int i=0;
|
||||
while (list_elem)
|
||||
{
|
||||
char* typeID = "{0000000000000-0000-0000-000000000000}";
|
||||
set_hobj_attr_value(id_TypeID, list_elem, typeID);
|
||||
objcts[i++] = ObjectFromHandle(list_elem);
|
||||
get_next_item(list_elem,&list_elem);
|
||||
}
|
||||
|
||||
retVal = sgCGroup::CreateGroup(objcts,resList.num);
|
||||
|
||||
if (reservObj)
|
||||
{
|
||||
o_free(reservObj,NULL);
|
||||
}
|
||||
free(objcts);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
sgCGroup* sgBoolean::IntersectionContour(const sgC3DObject& aOb,const sgC3DObject& bOb)
|
||||
{
|
||||
sgCGroup* retVal=NULL;
|
||||
|
||||
LISTH resList;
|
||||
init_listh(&resList);
|
||||
|
||||
hOBJ reservObj = NULL;
|
||||
|
||||
if (boolean_operation(GetObjectHandle(&aOb), GetObjectHandle(&bOb),LINE_INTER,&resList)!=OSTRUE)
|
||||
{
|
||||
//assert(0);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
if (resList.num<1)
|
||||
return retVal;
|
||||
|
||||
sgCObject** objcts = (sgCObject**)malloc(sizeof(sgCObject*)*resList.num);
|
||||
hOBJ list_elem = resList.hhead;
|
||||
int i=0;
|
||||
while (list_elem)
|
||||
{
|
||||
char* typeID = "{0000000000000-0000-0000-000000000000}";
|
||||
set_hobj_attr_value(id_TypeID, list_elem, typeID);
|
||||
objcts[i++] = ObjectFromHandle(list_elem);
|
||||
get_next_item(list_elem,&list_elem);
|
||||
}
|
||||
|
||||
retVal = sgCGroup::CreateGroup(objcts,resList.num);
|
||||
|
||||
if (reservObj)
|
||||
{
|
||||
o_free(reservObj,NULL);
|
||||
}
|
||||
free(objcts);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
sgCGroup* sgBoolean::Section(const sgC3DObject& obj, const SG_VECTOR& planeNormal,
|
||||
sgFloat planeD)
|
||||
{
|
||||
sgCGroup* retVal=NULL;
|
||||
|
||||
LISTH resList;
|
||||
init_listh(&resList);
|
||||
|
||||
D_PLANE plane;
|
||||
memcpy(&plane.v, &planeNormal, sizeof(SG_VECTOR));
|
||||
plane.d = planeD;
|
||||
|
||||
LISTH obj_list;
|
||||
|
||||
init_listh(&obj_list);
|
||||
|
||||
attach_item_tail_z(SEL_LIST, &obj_list, GetObjectHandle(&obj));
|
||||
|
||||
if (!cut(&obj_list, SEL_LIST, &plane, &resList))
|
||||
{
|
||||
//assert(0);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
detach_item_z(SEL_LIST, &obj_list, GetObjectHandle(&obj));
|
||||
init_listh(&obj_list);
|
||||
|
||||
if (resList.num<1)
|
||||
return retVal;
|
||||
|
||||
sgCObject** objcts = (sgCObject**)malloc(sizeof(sgCObject*)*resList.num);
|
||||
hOBJ list_elem = resList.hhead;
|
||||
int i=0;
|
||||
while (list_elem)
|
||||
{
|
||||
char* typeID = "{0000000000000-0000-0000-000000000000}";
|
||||
set_hobj_attr_value(id_TypeID, list_elem, typeID);
|
||||
objcts[i++] = ObjectFromHandle(list_elem);
|
||||
get_next_item(list_elem,&list_elem);
|
||||
}
|
||||
|
||||
retVal = sgCGroup::CreateGroup(objcts,resList.num);
|
||||
|
||||
free(objcts);
|
||||
|
||||
return retVal;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
#include "..//Core//sg.h"
|
||||
|
||||
sgCBox::sgCBox():sgC3DObject()
|
||||
{
|
||||
}
|
||||
|
||||
sgCBox::~sgCBox()
|
||||
{
|
||||
}
|
||||
|
||||
sgCBox::sgCBox(SG_OBJ_HANDLE objH):sgC3DObject(objH)
|
||||
{
|
||||
char* typeID = "{0000000000000-0000-0001-000000000009}";
|
||||
set_hobj_attr_value(id_TypeID, objH, typeID);
|
||||
|
||||
PostCreate();
|
||||
|
||||
}
|
||||
|
||||
sgCBox* sgCBox::Create(sgFloat sizeX, sgFloat sizeY, sgFloat sizeZ)
|
||||
{
|
||||
if (sizeX<eps_d ||
|
||||
sizeY<eps_d ||
|
||||
sizeZ<eps_d)
|
||||
return NULL;
|
||||
sgFloat par[3];
|
||||
par[0] = sizeX;
|
||||
par[1] = sizeY;
|
||||
par[2] = sizeZ;
|
||||
|
||||
hOBJ hO = create_primitive_obj(BOX, par);
|
||||
assert(hO);
|
||||
|
||||
sgCBox* newBox=new sgCBox(hO);
|
||||
|
||||
newBox->PostCreate();
|
||||
|
||||
return newBox;
|
||||
}
|
||||
|
||||
|
||||
void sgCBox::GetGeometry(SG_BOX& res) const
|
||||
{
|
||||
lpOBJ obj = static_cast<lpOBJ>(GetObjectHandle(this));
|
||||
assert(obj);
|
||||
|
||||
lpGEO_BREP geo = (lpGEO_BREP)(obj->geo_data);
|
||||
assert(geo);
|
||||
|
||||
LNP lnp;
|
||||
|
||||
if ( !read_elem(&vd_brep,geo->num,&lnp) )
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
|
||||
lpCSG csg = static_cast<lpCSG>(lnp.hcsg);
|
||||
assert(csg);
|
||||
|
||||
memcpy(&res, csg->data, csg->size);
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
#include "..//Core//sg.h"
|
||||
|
||||
// a = new SG_POINT[]. delete[] ;
|
||||
//static SG_POINT* CalculateCirclePoints(SG_CIRCLE* circ, int& pnts_count);
|
||||
|
||||
static SG_POINT circle_points_buffer[NUM_SEGMENTS];
|
||||
|
||||
static SG_POINT* GetPointsFromCircleGeo(const SG_CIRCLE* circ, int& pnts_count)
|
||||
{
|
||||
D_POINT p1_2D;
|
||||
D_POINT p2_2D;
|
||||
D_POINT vb, ve, vc;
|
||||
D_POINT p1_3D;
|
||||
D_POINT p2_3D;
|
||||
|
||||
short n;
|
||||
sgFloat dx, dy, dd, sp, cp;
|
||||
MATR mFrom2DTo3D;
|
||||
MATR mFrom3DTo2D;
|
||||
|
||||
lpGEO_CIRCLE circData = (lpGEO_CIRCLE)circ;
|
||||
|
||||
o_hcunit(mFrom3DTo2D);
|
||||
o_tdtran(mFrom3DTo2D, dpoint_inv(&circData->vc, &vc));
|
||||
o_hcrot1(mFrom3DTo2D, &circData->n);
|
||||
|
||||
SG_POINT drP1,drP2;
|
||||
|
||||
o_minv(mFrom3DTo2D,mFrom2DTo3D);
|
||||
|
||||
o_hcncrd(mFrom3DTo2D, &circData->vc, &vc);
|
||||
|
||||
dpoint_copy(&vb, &vc);
|
||||
vb.x += circData->r;
|
||||
dpoint_copy(&ve, &vb);
|
||||
|
||||
pnts_count = n = NUM_SEGMENTS;
|
||||
memset(circle_points_buffer,0,sizeof(SG_POINT)*pnts_count);
|
||||
|
||||
dd = (2*M_PI)/n;
|
||||
|
||||
sp = sin(dd);
|
||||
cp = cos(dd);
|
||||
dx = vb.x - vc.x;
|
||||
dy = vb.y - vc.y;
|
||||
dpoint_copy( &p1_2D, &vb);
|
||||
o_hcncrd(mFrom2DTo3D, &p1_2D, &p1_3D);
|
||||
int i=0;
|
||||
while(--n){
|
||||
dd = dx;
|
||||
dx = dx*cp - dy*sp;
|
||||
dy = dd*sp + dy*cp;
|
||||
p2_2D.x = vc.x + dx;
|
||||
p2_2D.y = vc.y + dy;
|
||||
p2_2D.z = 0.;
|
||||
o_hcncrd(mFrom2DTo3D, &p2_2D, &p2_3D);
|
||||
drP1.x = p1_3D.x; drP1.y = p1_3D.y; drP1.z = p1_3D.z;
|
||||
drP2.x = p2_3D.x; drP2.y = p2_3D.y; drP2.z = p2_3D.z;
|
||||
//lineDrawFunc(&drP1, &drP2);
|
||||
circle_points_buffer[i++] = drP1;
|
||||
dpoint_copy(&p1_2D, &p2_2D);
|
||||
dpoint_copy(&p1_3D, &p2_3D);
|
||||
}
|
||||
circle_points_buffer[i++] = drP2;
|
||||
/*dpoint_copy( &p2_2D, &ve);
|
||||
o_hcncrd(mFrom2DTo3D, &p2_2D, &p2_3D);
|
||||
drP1.x = p1_3D.x; drP1.y = p1_3D.y; drP1.z = p1_3D.z;
|
||||
drP2.x = p2_3D.x; drP2.y = p2_3D.y; drP2.z = p2_3D.z;*/
|
||||
//lineDrawFunc(&drP1, &drP2);
|
||||
|
||||
return circle_points_buffer;
|
||||
}
|
||||
|
||||
|
||||
bool SG_CIRCLE::FromCenterRadiusNormal(const SG_POINT& cen,
|
||||
sgFloat rad,
|
||||
const SG_VECTOR& nor)
|
||||
{
|
||||
if (rad<DBL_EPSILON)
|
||||
{
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_NON_POSITIVE;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((fabs(nor.x)+fabs(nor.y)+fabs(nor.z))<DBL_EPSILON)
|
||||
{
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_ZERO_LENGTH;
|
||||
return false;
|
||||
}
|
||||
center = cen;
|
||||
radius = rad;
|
||||
normal = nor;
|
||||
global_sg_error = SG_ER_SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SG_CIRCLE::FromThreePoints(const SG_POINT& p1,
|
||||
const SG_POINT& p2,
|
||||
const SG_POINT& p3)
|
||||
{
|
||||
sgFloat tmpD;
|
||||
if (!sgSpaceMath::PlaneFromPoints(p1,p2,p3,normal,tmpD))
|
||||
{
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_CONFLICT_BEETWEEN_ARGS;
|
||||
return false;
|
||||
}
|
||||
if (!sgSpaceMath::NormalVector(normal))
|
||||
{
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_CONFLICT_BEETWEEN_ARGS;
|
||||
return false;
|
||||
}
|
||||
|
||||
MATR mFrom2DTo3D;
|
||||
MATR mFrom3DTo2D;
|
||||
|
||||
o_hcunit(mFrom3DTo2D);
|
||||
lpD_POINT tmpP = reinterpret_cast<lpD_POINT>(&normal);
|
||||
o_hcrot1(mFrom3DTo2D, tmpP);
|
||||
o_minv(mFrom3DTo2D,mFrom2DTo3D);
|
||||
|
||||
D_POINT p_2D[3];
|
||||
|
||||
p_2D[0].x = p1.x;p_2D[0].y = p1.y;p_2D[0].z = p1.z;
|
||||
o_hcncrd(mFrom3DTo2D, &p_2D[0], &p_2D[0]);
|
||||
p_2D[1].x = p2.x;p_2D[1].y = p2.y;p_2D[1].z = p2.z;
|
||||
o_hcncrd(mFrom3DTo2D, &p_2D[1], &p_2D[1]);
|
||||
p_2D[2].x = p3.x;p_2D[2].y = p3.y;p_2D[2].z = p3.z;
|
||||
o_hcncrd(mFrom3DTo2D, &p_2D[2], &p_2D[2]);
|
||||
|
||||
GEO_ARC Arc;
|
||||
if (!arc_p_p_p(0,1,2,p_2D ,NULL,0,false,&Arc))
|
||||
{
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_CONFLICT_BEETWEEN_ARGS;
|
||||
return false;
|
||||
}
|
||||
|
||||
tmpP = reinterpret_cast<lpD_POINT>(¢er);
|
||||
Arc.vc.z = p_2D[0].z;
|
||||
o_hcncrd(mFrom2DTo3D,&Arc.vc,tmpP);
|
||||
|
||||
radius = sgSpaceMath::PointsDistance(center, p1);
|
||||
|
||||
global_sg_error = SG_ER_SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SG_CIRCLE::Draw(SG_DRAW_LINE_FUNC line_func) const
|
||||
{
|
||||
if (line_func==NULL)
|
||||
{
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_NULL_POINTER;
|
||||
return false;
|
||||
}
|
||||
int pcnt=0;
|
||||
SG_POINT* pnts=NULL;
|
||||
pnts = GetPointsFromCircleGeo(this,pcnt);
|
||||
for (int i=0;i<pcnt-1;i++)
|
||||
line_func(pnts+i, pnts+i+1);
|
||||
line_func(pnts+pcnt-1, pnts);
|
||||
global_sg_error = SG_ER_SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
sgCCircle::sgCCircle():sgC2DObject()
|
||||
, m_points(NULL)
|
||||
, m_points_count(0)
|
||||
{
|
||||
}
|
||||
|
||||
sgCCircle::sgCCircle(SG_OBJ_HANDLE objH):sgC2DObject(objH)
|
||||
, m_points(NULL)
|
||||
, m_points_count(0)
|
||||
{
|
||||
char* typeID = "{0000000000000-0000-0000-000000000003}";
|
||||
set_hobj_attr_value(id_TypeID, objH, typeID);
|
||||
|
||||
m_points_count = NUM_SEGMENTS;
|
||||
m_points = new SG_POINT[m_points_count];
|
||||
|
||||
SG_CIRCLE* crG = const_cast<SG_CIRCLE*>(GetGeometry());
|
||||
|
||||
memcpy(m_points,
|
||||
GetPointsFromCircleGeo(crG,m_points_count),
|
||||
sizeof(SG_POINT)*m_points_count);
|
||||
|
||||
memcpy(&m_plane_normal,&(crG->normal),sizeof(SG_VECTOR));
|
||||
sgSpaceMath::PlaneFromNormalAndPoint(crG->center,m_plane_normal,m_plane_D);
|
||||
|
||||
PostCreate();
|
||||
}
|
||||
|
||||
|
||||
bool sgCCircle::ApplyTempMatrix()
|
||||
{
|
||||
if (!sgCObject::ApplyTempMatrix())
|
||||
return false;
|
||||
SG_CIRCLE* crG = const_cast<SG_CIRCLE*>(GetGeometry());
|
||||
memcpy(m_points,GetPointsFromCircleGeo(crG,m_points_count),
|
||||
sizeof(SG_POINT)*m_points_count);
|
||||
memcpy(&m_plane_normal,&(crG->normal),sizeof(SG_VECTOR));
|
||||
sgSpaceMath::PlaneFromNormalAndPoint(crG->center,m_plane_normal,m_plane_D);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
sgCCircle::~sgCCircle()
|
||||
{
|
||||
if (m_points)
|
||||
{
|
||||
delete[] m_points;
|
||||
m_points = NULL;
|
||||
m_points_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
sgCCircle* sgCCircle::Create(const SG_CIRCLE& cirG)
|
||||
{
|
||||
SG_VECTOR vvv = cirG.normal;
|
||||
if (cirG.radius<eps_d ||
|
||||
!sgSpaceMath::NormalVector(vvv))
|
||||
{
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_UNKNOWN;
|
||||
return NULL;
|
||||
}
|
||||
global_sg_error = SG_ER_SUCCESS;
|
||||
sgCCircle* newC=new sgCCircle;
|
||||
SetObjectHandle(newC, create_simple_obj_loc(OCIRCLE, const_cast<SG_CIRCLE*>(&cirG)));
|
||||
((lpOBJ)(GetObjectHandle(newC)))->extendedClass = newC;
|
||||
|
||||
char* typeID = "{0000000000000-0000-0000-000000000003}";
|
||||
set_hobj_attr_value(id_TypeID, GetObjectHandle(newC), typeID);
|
||||
|
||||
newC->m_points_count = NUM_SEGMENTS;
|
||||
newC->m_points = new SG_POINT[newC->m_points_count];
|
||||
|
||||
SG_CIRCLE* crG = const_cast<SG_CIRCLE*>(newC->GetGeometry());
|
||||
memcpy(newC->m_points,
|
||||
GetPointsFromCircleGeo(crG,newC->m_points_count),
|
||||
sizeof(SG_POINT)*newC->m_points_count);
|
||||
|
||||
memcpy(&(newC->m_plane_normal),&(crG->normal),sizeof(SG_VECTOR));
|
||||
sgSpaceMath::PlaneFromNormalAndPoint(crG->center,
|
||||
newC->m_plane_normal,newC->m_plane_D);
|
||||
|
||||
newC->PostCreate();
|
||||
|
||||
return newC;
|
||||
}
|
||||
|
||||
const SG_CIRCLE* sgCCircle::GetGeometry() const
|
||||
{
|
||||
lpOBJ pobj = (lpOBJ)(GetObjectHandle(this));
|
||||
return static_cast<SG_CIRCLE*>((void*)(pobj->geo_data));
|
||||
}
|
||||
|
||||
int sgCCircle::GetPointsCount() const
|
||||
{
|
||||
return m_points_count;
|
||||
}
|
||||
|
||||
const SG_POINT* sgCCircle::GetPoints() const
|
||||
{
|
||||
return m_points;
|
||||
}
|
||||
|
||||
bool sgCCircle::IsClosed() const {return true;}
|
||||
bool sgCCircle::IsPlane(SG_VECTOR* plN,sgFloat* plD) const
|
||||
{
|
||||
if (plN)
|
||||
*plN = m_plane_normal;
|
||||
if (plD)
|
||||
*plD = m_plane_D;
|
||||
return true;
|
||||
}
|
||||
bool sgCCircle::IsLinear() const {return false;}
|
||||
bool sgCCircle::IsSelfIntersecting() const {return false;}
|
||||
@@ -0,0 +1,73 @@
|
||||
#include "..//Core//sg.h"
|
||||
|
||||
sgCCone::sgCCone():sgC3DObject()
|
||||
{
|
||||
}
|
||||
|
||||
sgCCone::~sgCCone()
|
||||
{
|
||||
}
|
||||
|
||||
sgCCone::sgCCone(SG_OBJ_HANDLE objH):sgC3DObject(objH)
|
||||
{
|
||||
char* typeID = "{0000000000000-0000-0004-000000000009}";
|
||||
set_hobj_attr_value(id_TypeID, objH, typeID);
|
||||
|
||||
PostCreate();
|
||||
|
||||
}
|
||||
|
||||
sgCCone* sgCCone::Create(sgFloat rad_1,sgFloat rad_2,sgFloat heig, short merid)
|
||||
{
|
||||
if ((rad_1<eps_d &&
|
||||
rad_2<eps_d) ||
|
||||
heig<eps_d ||
|
||||
merid<2)
|
||||
return NULL;
|
||||
|
||||
sgFloat par[4];
|
||||
par[0] = rad_1;
|
||||
par[1] = rad_2;
|
||||
par[2] = heig;
|
||||
par[3] = (sgFloat)merid;
|
||||
|
||||
hOBJ hO = create_primitive_obj(CONE, par);
|
||||
assert(hO);
|
||||
|
||||
sgCCone* newC=new sgCCone(hO);
|
||||
|
||||
newC->PostCreate();
|
||||
|
||||
return newC;
|
||||
}
|
||||
|
||||
|
||||
void sgCCone::GetGeometry(SG_CONE& res) const
|
||||
{
|
||||
lpOBJ obj = static_cast<lpOBJ>(GetObjectHandle(this));
|
||||
assert(obj);
|
||||
|
||||
lpGEO_BREP geo = (lpGEO_BREP)(obj->geo_data);
|
||||
assert(geo);
|
||||
|
||||
LNP lnp;
|
||||
|
||||
if ( !read_elem(&vd_brep,geo->num,&lnp) )
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
|
||||
lpCSG csg = static_cast<lpCSG>(lnp.hcsg);
|
||||
assert(csg);
|
||||
|
||||
sgFloat* pars = (sgFloat*)malloc(csg->size);
|
||||
|
||||
memcpy(pars, csg->data, csg->size);
|
||||
|
||||
res.Radius1 = pars[0];
|
||||
res.Radius2 = pars[1];
|
||||
res.Height = pars[2];
|
||||
res.MeridiansCount = static_cast<short>(pars[3]);
|
||||
|
||||
free(pars);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
#include "..//Core//sg.h"
|
||||
|
||||
sgCCylinder::sgCCylinder():sgC3DObject()
|
||||
{
|
||||
}
|
||||
|
||||
sgCCylinder::~sgCCylinder()
|
||||
{
|
||||
}
|
||||
|
||||
sgCCylinder::sgCCylinder(SG_OBJ_HANDLE objH):sgC3DObject(objH)
|
||||
{
|
||||
char* typeID = "{0000000000000-0000-0003-000000000009}";
|
||||
set_hobj_attr_value(id_TypeID, objH, typeID);
|
||||
|
||||
PostCreate();
|
||||
|
||||
}
|
||||
|
||||
sgCCylinder* sgCCylinder::Create(sgFloat rad, sgFloat heig, short merid)
|
||||
{
|
||||
if (rad<eps_d ||
|
||||
heig<eps_d ||
|
||||
merid<2)
|
||||
return NULL;
|
||||
|
||||
sgFloat par[3];
|
||||
par[0] = rad;
|
||||
par[1] = heig;
|
||||
par[2] = (sgFloat)merid;
|
||||
|
||||
hOBJ hO = create_primitive_obj(CYL, par);
|
||||
assert(hO);
|
||||
|
||||
sgCCylinder* newC=new sgCCylinder(hO);
|
||||
|
||||
newC->PostCreate();
|
||||
|
||||
return newC;
|
||||
}
|
||||
|
||||
|
||||
void sgCCylinder::GetGeometry(SG_CYLINDER& res) const
|
||||
{
|
||||
lpOBJ obj = static_cast<lpOBJ>(GetObjectHandle(this));
|
||||
assert(obj);
|
||||
|
||||
lpGEO_BREP geo = (lpGEO_BREP)(obj->geo_data);
|
||||
assert(geo);
|
||||
|
||||
LNP lnp;
|
||||
|
||||
if ( !read_elem(&vd_brep,geo->num,&lnp) )
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
|
||||
lpCSG csg = static_cast<lpCSG>(lnp.hcsg);
|
||||
assert(csg);
|
||||
|
||||
sgFloat* pars = (sgFloat*)malloc(csg->size);
|
||||
|
||||
memcpy(pars, csg->data, csg->size);
|
||||
|
||||
res.Radius = pars[0];
|
||||
res.Height = pars[1];
|
||||
res.MeridiansCount = static_cast<short>(pars[2]);
|
||||
|
||||
free(pars);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,80 @@
|
||||
#include "..//Core//sg.h"
|
||||
|
||||
sgCEllipsoid::sgCEllipsoid():sgC3DObject()
|
||||
{
|
||||
}
|
||||
|
||||
sgCEllipsoid::~sgCEllipsoid()
|
||||
{
|
||||
}
|
||||
|
||||
sgCEllipsoid::sgCEllipsoid(SG_OBJ_HANDLE objH):sgC3DObject(objH)
|
||||
{
|
||||
char* typeID = "{0000000000000-0000-0008-000000000009}";
|
||||
set_hobj_attr_value(id_TypeID, objH, typeID);
|
||||
|
||||
PostCreate();
|
||||
|
||||
}
|
||||
|
||||
sgCEllipsoid* sgCEllipsoid::Create(sgFloat radius1, sgFloat radius2, sgFloat radius3,
|
||||
short merid_cnt, short parall_cnt)
|
||||
{
|
||||
|
||||
if (radius1<eps_d ||
|
||||
radius2<eps_d ||
|
||||
radius3<eps_d ||
|
||||
merid_cnt<2 ||
|
||||
parall_cnt<2)
|
||||
return NULL;
|
||||
|
||||
sgFloat par[5];
|
||||
|
||||
par[0] = radius1;
|
||||
par[1] = radius2;
|
||||
par[2] = radius3;
|
||||
par[3] = (sgFloat)merid_cnt;
|
||||
par[4] = (sgFloat)parall_cnt;
|
||||
|
||||
|
||||
hOBJ hO = create_primitive_obj(ELIPSOID, par);
|
||||
assert(hO);
|
||||
|
||||
sgCEllipsoid* newE=new sgCEllipsoid(hO);
|
||||
|
||||
newE->PostCreate();
|
||||
|
||||
return newE;
|
||||
}
|
||||
|
||||
|
||||
void sgCEllipsoid::GetGeometry(SG_ELLIPSOID& res) const
|
||||
{
|
||||
lpOBJ obj = static_cast<lpOBJ>(GetObjectHandle(this));
|
||||
assert(obj);
|
||||
|
||||
lpGEO_BREP geo = (lpGEO_BREP)(obj->geo_data);
|
||||
assert(geo);
|
||||
|
||||
LNP lnp;
|
||||
|
||||
if ( !read_elem(&vd_brep,geo->num,&lnp) )
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
|
||||
lpCSG csg = static_cast<lpCSG>(lnp.hcsg);
|
||||
assert(csg);
|
||||
|
||||
sgFloat* pars = (sgFloat*)malloc(csg->size);
|
||||
|
||||
memcpy(pars, csg->data, csg->size);
|
||||
|
||||
res.Radius1 = pars[0];
|
||||
res.Radius2 = pars[1];
|
||||
res.Radius3 = pars[2];
|
||||
res.MeridiansCount = static_cast<short>(pars[3]);
|
||||
res.ParallelsCount = static_cast<short>(pars[4]);
|
||||
|
||||
free(pars);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
#include "..//Core//sg.h"
|
||||
#include "..//Core//common_hdr.h"
|
||||
|
||||
sgCFont::sgCFont(void* hndl, unsigned long lngth, long iden)
|
||||
{
|
||||
m_handle = hndl;
|
||||
m_length = lngth;
|
||||
m_id = iden;
|
||||
}
|
||||
|
||||
sgCFont::~sgCFont()
|
||||
{
|
||||
if (m_handle)
|
||||
{
|
||||
SGFree(m_handle);
|
||||
}
|
||||
m_handle = NULL;
|
||||
m_length = 0;
|
||||
m_id = 0;
|
||||
}
|
||||
|
||||
const SG_FONT_DATA* const sgCFont::GetFontData() const
|
||||
{
|
||||
if (!m_handle)
|
||||
{
|
||||
if (m_id==0)
|
||||
{
|
||||
assert(0);
|
||||
return NULL;
|
||||
}
|
||||
if(0 ==(m_handle = alloc_and_get_ft_value(m_id, &m_length)))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return reinterpret_cast<SG_FONT_DATA*>(m_handle);
|
||||
}
|
||||
|
||||
sgCFont* sgCFont::LoadFont(const char* path, char* comment, short commentLength)
|
||||
{
|
||||
ULONG lenF;
|
||||
lpFONT font=NULL;
|
||||
short errcode=-1;
|
||||
|
||||
char drive [MAXDRIVE];
|
||||
char dir [MAXDIR];
|
||||
char file [MAXFILE];
|
||||
char ext [MAXEXT];
|
||||
|
||||
fnsplit(path, drive, dir, file, ext);
|
||||
|
||||
if ((strlen(file)+strlen(ext))>15)
|
||||
return NULL;
|
||||
|
||||
if(0 ==(font = load_font(const_cast<char*>(path),&lenF,comment,commentLength, &errcode)))
|
||||
return NULL;
|
||||
|
||||
sgCFont* resF = new sgCFont(font,lenF,0);
|
||||
|
||||
return resF;
|
||||
}
|
||||
|
||||
bool sgCFont::UnloadFont(sgCFont* fnt)
|
||||
{
|
||||
if (!fnt || fnt->m_id!=0)
|
||||
return false;
|
||||
|
||||
delete fnt;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,678 @@
|
||||
#include "..//Core//sg.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
class GroupChildsList : public IObjectsList
|
||||
{
|
||||
sgCGroup* m_group;
|
||||
public:
|
||||
GroupChildsList(sgCGroup* gr) {m_group = gr;};
|
||||
|
||||
virtual int GetCount() const
|
||||
{
|
||||
lpOBJ pobj = (lpOBJ)GetObjectHandle(m_group);
|
||||
|
||||
if (pobj->type==OGROUP)
|
||||
return (((lpGEO_GROUP)(pobj->geo_data))->listh.num);
|
||||
else
|
||||
return 0;
|
||||
};
|
||||
virtual sgCObject* GetHead() const
|
||||
{
|
||||
lpOBJ pobj = (lpOBJ)GetObjectHandle(m_group);
|
||||
|
||||
if (pobj->type==OGROUP)
|
||||
{
|
||||
VADR objH = (((lpGEO_GROUP)(pobj->geo_data))->listh.hhead);
|
||||
return ((lpOBJ)objH)->extendedClass;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
};
|
||||
virtual sgCObject* GetNext(sgCObject* c_obj) const
|
||||
{
|
||||
hOBJ nextElem;
|
||||
get_next_item(GetObjectHandle(c_obj),&nextElem);
|
||||
if (nextElem==NULL)
|
||||
return NULL;
|
||||
return ((lpOBJ)nextElem)->extendedClass;
|
||||
};
|
||||
virtual sgCObject* GetTail() const
|
||||
{
|
||||
lpOBJ pobj = (lpOBJ)GetObjectHandle(m_group);
|
||||
|
||||
if (pobj->type==OGROUP)
|
||||
{
|
||||
VADR objH = (((lpGEO_GROUP)(pobj->geo_data))->listh.htail);
|
||||
return ((lpOBJ)objH)->extendedClass;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
};
|
||||
virtual sgCObject* GetPrev(sgCObject* c_obj) const
|
||||
{
|
||||
hOBJ prElem;
|
||||
get_prev_item(GetObjectHandle(c_obj),&prElem);
|
||||
if (prElem==NULL)
|
||||
return NULL;
|
||||
return ((lpOBJ)prElem)->extendedClass;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
sgCGroup::sgCGroup():sgCObject()
|
||||
{
|
||||
m_children = new GroupChildsList(this);
|
||||
}
|
||||
|
||||
sgCGroup::sgCGroup(SG_OBJ_HANDLE objH):sgCObject(objH)
|
||||
{
|
||||
lpOBJ pobj = (lpOBJ)objH;
|
||||
if (pobj->type!=OGROUP)
|
||||
return;
|
||||
|
||||
lpGEO_GROUP geo;
|
||||
hOBJ list_elem;
|
||||
|
||||
geo = (lpGEO_GROUP)pobj->geo_data;
|
||||
|
||||
list_elem = geo->listh.hhead;
|
||||
while (list_elem)
|
||||
{
|
||||
ObjectFromHandle(list_elem);
|
||||
get_next_item(list_elem,&list_elem);
|
||||
}
|
||||
|
||||
m_children = new GroupChildsList(this);
|
||||
|
||||
PostCreate();
|
||||
}
|
||||
|
||||
sgCGroup::~sgCGroup()
|
||||
{
|
||||
delete m_children;
|
||||
}
|
||||
|
||||
IObjectsList* sgCGroup::GetChildrenList() const
|
||||
{
|
||||
return m_children;
|
||||
}
|
||||
|
||||
bool sgCGroup::SetAttribute(SG_OBJECT_ATTR_ID prId, unsigned short prop)
|
||||
{
|
||||
sgCObject* curObj = GetChildrenList()->GetHead();
|
||||
while (curObj)
|
||||
{
|
||||
curObj->SetAttribute(prId, prop);
|
||||
curObj = GetChildrenList()->GetNext(curObj);
|
||||
}
|
||||
return sgCObject::SetAttribute(prId, prop);
|
||||
}
|
||||
|
||||
bool sgCGroup::ApplyTempMatrix()
|
||||
{
|
||||
//if (!sgCObject::ApplyTempMatrix())
|
||||
// return false;
|
||||
|
||||
sgCObject* curObj = GetChildrenList()->GetHead();
|
||||
while (curObj)
|
||||
{
|
||||
curObj->InitTempMatrix()->SetMatrix(GetTempMatrix());
|
||||
if (!curObj->ApplyTempMatrix())
|
||||
{
|
||||
curObj->DestroyTempMatrix();
|
||||
return false;
|
||||
}
|
||||
curObj->DestroyTempMatrix();
|
||||
curObj = GetChildrenList()->GetNext(curObj);
|
||||
}
|
||||
|
||||
if (!get_object_limits(GetObjectHandle(this),reinterpret_cast<D_POINT*>(&m_min),
|
||||
reinterpret_cast<D_POINT*>(&m_max)))
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
if (fabs(m_min.x-scene_min.x)<0.0000001 ||
|
||||
fabs(m_min.y-scene_min.y)<0.0000001 ||
|
||||
fabs(m_min.z-scene_min.z)<0.0000001 ||
|
||||
fabs(m_max.x-scene_max.x)<0.0000001 ||
|
||||
fabs(m_max.y-scene_max.y)<0.0000001 ||
|
||||
fabs(m_max.z-scene_max.z)<0.0000001)
|
||||
get_scene_limits();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class ContChildsList : public IObjectsList
|
||||
{
|
||||
sgCContour* m_cont;
|
||||
public:
|
||||
ContChildsList(sgCContour* cn) {m_cont = cn;};
|
||||
|
||||
virtual int GetCount() const
|
||||
{
|
||||
lpOBJ pobj = (lpOBJ)GetObjectHandle(m_cont);
|
||||
|
||||
if (pobj->type==OPATH)
|
||||
return (((lpGEO_PATH)(pobj->geo_data))->listh.num);
|
||||
else
|
||||
return 0;
|
||||
};
|
||||
virtual sgCObject* GetHead() const
|
||||
{
|
||||
lpOBJ pobj = (lpOBJ)GetObjectHandle(m_cont);
|
||||
|
||||
if (pobj->type==OPATH)
|
||||
{
|
||||
VADR objH = (((lpGEO_PATH)(pobj->geo_data))->listh.hhead);
|
||||
return ((lpOBJ)objH)->extendedClass;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
};
|
||||
virtual sgCObject* GetNext(sgCObject* c_obj) const
|
||||
{
|
||||
hOBJ nextElem;
|
||||
get_next_item(GetObjectHandle(c_obj),&nextElem);
|
||||
if (nextElem==NULL)
|
||||
return NULL;
|
||||
return ((lpOBJ)nextElem)->extendedClass;
|
||||
};
|
||||
virtual sgCObject* GetTail() const
|
||||
{
|
||||
lpOBJ pobj = (lpOBJ)GetObjectHandle(m_cont);
|
||||
|
||||
if (pobj->type==OPATH)
|
||||
{
|
||||
VADR objH = (((lpGEO_PATH)(pobj->geo_data))->listh.htail);
|
||||
return ((lpOBJ)objH)->extendedClass;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
};
|
||||
virtual sgCObject* GetPrev(sgCObject* c_obj) const
|
||||
{
|
||||
hOBJ prElem;
|
||||
get_prev_item(GetObjectHandle(c_obj),&prElem);
|
||||
if (prElem==NULL)
|
||||
return NULL;
|
||||
return ((lpOBJ)prElem)->extendedClass;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
sgCContour::sgCContour():sgC2DObject()
|
||||
{
|
||||
m_children = new ContChildsList(this);
|
||||
}
|
||||
|
||||
sgCContour::sgCContour(SG_OBJ_HANDLE objH):sgC2DObject(objH)
|
||||
{
|
||||
lpOBJ pobj = (lpOBJ)objH;
|
||||
if (pobj->type!=OPATH)
|
||||
return;
|
||||
|
||||
lpGEO_PATH geo = (lpGEO_PATH)pobj->geo_data;
|
||||
hOBJ list_elem = geo->listh.hhead;;
|
||||
|
||||
while (list_elem)
|
||||
{
|
||||
ObjectFromHandle(list_elem);
|
||||
get_next_item(list_elem,&list_elem);
|
||||
}
|
||||
|
||||
|
||||
if (is_path_on_one_line(objH))
|
||||
{
|
||||
pobj->status |= ST_ON_LINE;
|
||||
pobj->status &= ~ST_FLAT;
|
||||
}
|
||||
else
|
||||
{
|
||||
pobj->status &= ~ST_ON_LINE;
|
||||
D_PLANE plane;
|
||||
if (set_flat_on_path(objH, &plane))
|
||||
{
|
||||
pobj->status |= ST_FLAT;
|
||||
memcpy(&m_plane_normal,&plane.v,sizeof(D_POINT));
|
||||
m_plane_D =plane.d;
|
||||
}
|
||||
else
|
||||
{
|
||||
pobj->status &= ~ST_FLAT;
|
||||
}
|
||||
}
|
||||
|
||||
m_children = new ContChildsList(this);
|
||||
|
||||
PostCreate();
|
||||
}
|
||||
|
||||
sgCContour::~sgCContour()
|
||||
{
|
||||
delete m_children;
|
||||
}
|
||||
|
||||
|
||||
IObjectsList* sgCContour::GetChildrenList() const
|
||||
{
|
||||
return m_children;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool sgCContour::SetAttribute(SG_OBJECT_ATTR_ID prId, unsigned short prop)
|
||||
{
|
||||
sgCObject* curObj = GetChildrenList()->GetHead();
|
||||
while (curObj)
|
||||
{
|
||||
curObj->SetAttribute(prId, prop);
|
||||
curObj = GetChildrenList()->GetNext(curObj);
|
||||
}
|
||||
return sgCObject::SetAttribute(prId, prop);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool sgCContour::ApplyTempMatrix()
|
||||
{
|
||||
//if (!sgCObject::ApplyTempMatrix())
|
||||
// return false;
|
||||
|
||||
sgCObject* curObj = GetChildrenList()->GetHead();
|
||||
while (curObj)
|
||||
{
|
||||
curObj->InitTempMatrix()->SetMatrix(GetTempMatrix());
|
||||
if (!curObj->ApplyTempMatrix())
|
||||
{
|
||||
curObj->DestroyTempMatrix();
|
||||
return false;
|
||||
}
|
||||
curObj->DestroyTempMatrix();
|
||||
curObj = GetChildrenList()->GetNext(curObj);
|
||||
}
|
||||
|
||||
lpOBJ obj = (lpOBJ)GetObjectHandle(this);
|
||||
if (obj->status & ST_FLAT)
|
||||
{
|
||||
D_PLANE plane;
|
||||
|
||||
// ROBLOX change
|
||||
//#if (SG_CURRENT_PLATFORM==SG_PLATFORM_IOS)
|
||||
sgFloat savingEpsD = eps_d;
|
||||
eps_d *=100.0; // fix for sgFloat = float (not double )
|
||||
//#endif
|
||||
if (set_flat_on_path(GetObjectHandle(this), &plane))
|
||||
{
|
||||
obj->status |= ST_FLAT;
|
||||
memcpy(&m_plane_normal,&plane.v,sizeof(D_POINT));
|
||||
m_plane_D =plane.d;
|
||||
}
|
||||
else
|
||||
{
|
||||
//assert(0);
|
||||
obj->status &= ~ST_FLAT;
|
||||
}
|
||||
// ROBLOX change
|
||||
//#if (SG_CURRENT_PLATFORM==SG_PLATFORM_IOS)
|
||||
eps_d = savingEpsD;
|
||||
//#endif
|
||||
}
|
||||
|
||||
if (!get_object_limits(GetObjectHandle(this),reinterpret_cast<D_POINT*>(&m_min),
|
||||
reinterpret_cast<D_POINT*>(&m_max)))
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
if (fabs(m_min.x-scene_min.x)<0.0000001 ||
|
||||
fabs(m_min.y-scene_min.y)<0.0000001 ||
|
||||
fabs(m_min.z-scene_min.z)<0.0000001 ||
|
||||
fabs(m_max.x-scene_max.x)<0.0000001 ||
|
||||
fabs(m_max.y-scene_max.y)<0.0000001 ||
|
||||
fabs(m_max.z-scene_max.z)<0.0000001)
|
||||
get_scene_limits();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool sgCContour::IsClosed() const
|
||||
{
|
||||
if (((lpOBJ)GetObjectHandle(this))->status & ST_CLOSE)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool sgCContour::IsPlane(SG_VECTOR* plN,sgFloat* plD) const
|
||||
{
|
||||
if (((lpOBJ)GetObjectHandle(this))->status & ST_FLAT)
|
||||
{
|
||||
if (plN)
|
||||
*plN = m_plane_normal;
|
||||
if (plD)
|
||||
*plD = m_plane_D;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool sgCContour::IsLinear() const
|
||||
{
|
||||
if (((lpOBJ)GetObjectHandle(this))->status & ST_ON_LINE)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool sgCContour::IsSelfIntersecting() const
|
||||
{
|
||||
if (((lpOBJ)GetObjectHandle(this))->status & ST_SIMPLE)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SG_POINT beginP;
|
||||
SG_POINT endP;
|
||||
}POINT_PAIR;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SG_POINT Pnt;
|
||||
int indexOfPointObject;
|
||||
bool isExistPair;
|
||||
int indexOfPairObject;
|
||||
}GRAPH_VERTEX;
|
||||
|
||||
/*
|
||||
static void switch_st_direct(hOBJ hobj)
|
||||
{
|
||||
lpOBJ obj;
|
||||
|
||||
obj = (lpOBJ)hobj;
|
||||
obj->status ^= ST_DIRECT;
|
||||
}
|
||||
*/
|
||||
|
||||
static bool isExistObjectInArray(sgCObject** obArr, int cnt, sgCObject* ob)
|
||||
{
|
||||
for (int i=0;i<cnt;i++)
|
||||
if (obArr[i]==ob)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool sgCContour::TopologySort(sgCObject** objcts, int cnt)
|
||||
{
|
||||
POINT_PAIR* b_e_P = (POINT_PAIR*)malloc(sizeof(POINT_PAIR)*cnt);
|
||||
|
||||
int i,j;
|
||||
|
||||
//
|
||||
for (i=0;i<cnt;i++)
|
||||
{
|
||||
if (objcts[i]->GetType()==SG_OT_LINE)
|
||||
{
|
||||
sgCLine* ln = reinterpret_cast<sgCLine*>(objcts[i]);
|
||||
b_e_P[i].beginP = ln->GetGeometry()->p1;
|
||||
b_e_P[i].endP = ln->GetGeometry()->p2;
|
||||
}
|
||||
else
|
||||
if (objcts[i]->GetType()==SG_OT_ARC)
|
||||
{
|
||||
sgCArc* ar = reinterpret_cast<sgCArc*>(objcts[i]);
|
||||
b_e_P[i].beginP = ar->GetGeometry()->begin;
|
||||
b_e_P[i].endP = ar->GetGeometry()->end;
|
||||
}
|
||||
else
|
||||
if (objcts[i]->GetType()==SG_OT_CONTOUR)
|
||||
{
|
||||
sgCContour* cntr = reinterpret_cast<sgCContour*>(objcts[i]);
|
||||
if (cntr->IsClosed())
|
||||
{
|
||||
free(b_e_P);
|
||||
return false;
|
||||
}
|
||||
b_e_P[i].beginP = cntr->GetPointFromCoefficient(0.0);
|
||||
b_e_P[i].endP = cntr->GetPointFromCoefficient(1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
free(b_e_P);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
GRAPH_VERTEX* gr_Pnts = (GRAPH_VERTEX*)malloc(sizeof(GRAPH_VERTEX)*2*cnt);
|
||||
memset(gr_Pnts,0,sizeof(GRAPH_VERTEX)*2*cnt);
|
||||
|
||||
for (i=0;i<cnt;i++)
|
||||
{
|
||||
gr_Pnts[2*i].Pnt = b_e_P[i].beginP;
|
||||
gr_Pnts[2*i].indexOfPointObject = i;
|
||||
gr_Pnts[2*i].isExistPair = false;
|
||||
gr_Pnts[2*i].indexOfPairObject = -1;
|
||||
for (j=0;j<cnt;j++)
|
||||
{
|
||||
if (i!=j)
|
||||
{
|
||||
if (dpoint_eq((lpD_POINT)&(b_e_P[i].beginP),(lpD_POINT)&(b_e_P[j].beginP),eps_d))
|
||||
{
|
||||
gr_Pnts[2*i].isExistPair = true;
|
||||
gr_Pnts[2*i].indexOfPairObject = j;
|
||||
break;
|
||||
}
|
||||
if (dpoint_eq((lpD_POINT)&(b_e_P[i].beginP),(lpD_POINT)&(b_e_P[j].endP),eps_d))
|
||||
{
|
||||
gr_Pnts[2*i].isExistPair = true;
|
||||
gr_Pnts[2*i].indexOfPairObject = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gr_Pnts[2*i+1].Pnt = b_e_P[i].endP;
|
||||
gr_Pnts[2*i+1].indexOfPointObject = i;
|
||||
gr_Pnts[2*i+1].isExistPair = false;
|
||||
gr_Pnts[2*i+1].indexOfPairObject = -1;
|
||||
for (j=0;j<cnt;j++)
|
||||
{
|
||||
if (i!=j)
|
||||
{
|
||||
if (dpoint_eq((lpD_POINT)&(b_e_P[i].endP),(lpD_POINT)&(b_e_P[j].beginP),eps_d))
|
||||
{
|
||||
gr_Pnts[2*i+1].isExistPair = true;
|
||||
gr_Pnts[2*i+1].indexOfPairObject = j;
|
||||
break;
|
||||
}
|
||||
if (dpoint_eq((lpD_POINT)&(b_e_P[i].endP),(lpD_POINT)&(b_e_P[j].endP),eps_d))
|
||||
{
|
||||
gr_Pnts[2*i+1].isExistPair = true;
|
||||
gr_Pnts[2*i+1].indexOfPairObject = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(b_e_P);
|
||||
|
||||
int begInd= -1;
|
||||
int endInd = -1;
|
||||
|
||||
for (i=0;i<2*cnt;i++)
|
||||
{
|
||||
if(!gr_Pnts[i].isExistPair && begInd==-1 && endInd==-1)
|
||||
begInd = i;
|
||||
else
|
||||
if(!gr_Pnts[i].isExistPair && begInd!=-1 && endInd==-1)
|
||||
endInd = i;
|
||||
else
|
||||
if(!gr_Pnts[i].isExistPair && begInd!=-1 && endInd!=-1)
|
||||
{
|
||||
assert(0);
|
||||
free(gr_Pnts);
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*sgCObject** tmpArray = (sgCObject**)malloc(sizeof(sgCObject*)*cnt);
|
||||
memset(tmpArray,0,sizeof(sgCObject*)*cnt);
|
||||
|
||||
|
||||
if (begInd==-1 && endInd==-1) //
|
||||
{
|
||||
tmpArray[0] = objcts[gr_Pnts[0].indexOfPointObject];
|
||||
assert(gr_Pnts[0].indexOfPairObject!=-1);
|
||||
tmpArray[1] = objcts[gr_Pnts[0].indexOfPairObject];
|
||||
int lastInd = gr_Pnts[0].indexOfPairObject;
|
||||
gr_Pnts[0].indexOfPointObject = gr_Pnts[0].indexOfPairObject = -1;
|
||||
for (i=2;i<cnt;i++)
|
||||
{
|
||||
for (j=0;j<2*cnt;j++)
|
||||
{
|
||||
if (gr_Pnts[j].indexOfPointObject!=lastInd &&
|
||||
gr_Pnts[j].indexOfPairObject==lastInd)
|
||||
{
|
||||
tmpArray[i] = objcts[gr_Pnts[j].indexOfPointObject];
|
||||
for (int k=0;k<2*cnt;k++)
|
||||
if(gr_Pnts[k].indexOfPointObject==lastInd)
|
||||
gr_Pnts[k].indexOfPointObject=
|
||||
gr_Pnts[k].indexOfPairObject = -1;
|
||||
lastInd = gr_Pnts[j].indexOfPointObject;
|
||||
gr_Pnts[j].indexOfPointObject = gr_Pnts[j].indexOfPairObject = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (tmpArray[i]==NULL)
|
||||
{
|
||||
assert(0);
|
||||
free(gr_Pnts);
|
||||
free(tmpArray);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else //
|
||||
{
|
||||
tmpArray[0] = objcts[gr_Pnts[begInd].indexOfPointObject];
|
||||
int lastInd = gr_Pnts[begInd].indexOfPointObject;
|
||||
gr_Pnts[begInd].indexOfPointObject = -1;
|
||||
for (i=1;i<cnt-1;i++)
|
||||
{
|
||||
for (j=0;j<2*cnt;j++)
|
||||
{
|
||||
if (gr_Pnts[j].indexOfPointObject!=lastInd &&
|
||||
gr_Pnts[j].indexOfPairObject==lastInd)
|
||||
{
|
||||
tmpArray[i] = objcts[gr_Pnts[j].indexOfPointObject];
|
||||
for (int k=0;k<2*cnt;k++)
|
||||
if(gr_Pnts[k].indexOfPointObject==lastInd)
|
||||
gr_Pnts[k].indexOfPointObject=
|
||||
gr_Pnts[k].indexOfPairObject = -1;
|
||||
lastInd = gr_Pnts[j].indexOfPointObject;
|
||||
gr_Pnts[j].indexOfPointObject = gr_Pnts[j].indexOfPairObject = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (tmpArray[i]==NULL)
|
||||
{
|
||||
assert(0);
|
||||
free(gr_Pnts);
|
||||
free(tmpArray);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
tmpArray[cnt-1] = objcts[gr_Pnts[endInd].indexOfPointObject];
|
||||
}
|
||||
|
||||
|
||||
|
||||
memcpy(objcts,tmpArray,sizeof(sgCObject*)*cnt);
|
||||
|
||||
free(gr_Pnts);
|
||||
free(tmpArray);
|
||||
return true;*/
|
||||
|
||||
|
||||
sgCObject** tmpArray = (sgCObject**)malloc(sizeof(sgCObject*)*cnt);
|
||||
memset(tmpArray,0,sizeof(sgCObject*)*cnt);
|
||||
|
||||
if (begInd==-1 && endInd==-1) //
|
||||
tmpArray[0] = objcts[0];
|
||||
else
|
||||
{
|
||||
D_POINT tmpP;
|
||||
get_endpoint_on_path(GetObjectHandle(objcts[gr_Pnts[begInd].indexOfPointObject]),
|
||||
&tmpP,(OSTATUS)0);
|
||||
bool thisOrNot = (dpoint_eq((lpD_POINT)&(gr_Pnts[begInd].Pnt),(lpD_POINT)&(tmpP),eps_d)!=FALSE);
|
||||
if (!thisOrNot)
|
||||
{
|
||||
lpOBJ obj = (lpOBJ)(GetObjectHandle(objcts[gr_Pnts[begInd].indexOfPointObject]));
|
||||
obj->status ^= ST_DIRECT;
|
||||
}
|
||||
tmpArray[0] = objcts[gr_Pnts[begInd].indexOfPointObject];
|
||||
}
|
||||
free(gr_Pnts);
|
||||
|
||||
D_POINT begLast,endLast;
|
||||
get_endpoint_on_path(GetObjectHandle(tmpArray[0]),&begLast,(OSTATUS)0);
|
||||
D_POINT begFirst = begLast;
|
||||
get_endpoint_on_path(GetObjectHandle(tmpArray[0]),&endLast,(OSTATUS)ST_DIRECT);
|
||||
for (int i=1;i<cnt;i++)
|
||||
{
|
||||
for (int j=0;j<cnt;j++)
|
||||
{
|
||||
if (!isExistObjectInArray(tmpArray,i,objcts[j]))
|
||||
{
|
||||
D_POINT begCur,endCur;
|
||||
get_endpoint_on_path(GetObjectHandle(objcts[j]),&begCur,(OSTATUS)0);
|
||||
get_endpoint_on_path(GetObjectHandle(objcts[j]),&endCur,(OSTATUS)ST_DIRECT);
|
||||
if (dpoint_eq((lpD_POINT)&(endLast),(lpD_POINT)&(begCur),eps_d))
|
||||
{
|
||||
tmpArray[i] = objcts[j];
|
||||
begLast = begCur;
|
||||
endLast = endCur;
|
||||
break;
|
||||
}
|
||||
if (dpoint_eq((lpD_POINT)&(endLast),(lpD_POINT)&(endCur),eps_d))
|
||||
{
|
||||
lpOBJ obj = (lpOBJ)GetObjectHandle(objcts[j]);
|
||||
obj->status ^= ST_DIRECT;
|
||||
tmpArray[i] = objcts[j];
|
||||
begLast = endCur;
|
||||
endLast = begCur;
|
||||
break;
|
||||
}
|
||||
/*if (dpoint_eq((lpD_POINT)&(begFirst),(lpD_POINT)&(endCur),eps_d))
|
||||
{
|
||||
//
|
||||
tmpArray[cnt-1] = objcts[j];
|
||||
assert(i==cnt-1);
|
||||
goto endLabel;
|
||||
}*/
|
||||
/*if (dpoint_eq((lpD_POINT)&(begFirst),(lpD_POINT)&(begCur),eps_d))
|
||||
{
|
||||
//
|
||||
assert(0);
|
||||
free(tmpArray);
|
||||
return false;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(objcts,tmpArray,sizeof(sgCObject*)*cnt);
|
||||
|
||||
free(tmpArray);
|
||||
return true;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,60 @@
|
||||
#include "..//Core//sg.h"
|
||||
|
||||
sgCLine::sgCLine():sgC2DObject()
|
||||
{
|
||||
}
|
||||
|
||||
sgCLine::~sgCLine()
|
||||
{
|
||||
}
|
||||
|
||||
sgCLine::sgCLine(SG_OBJ_HANDLE objH):sgC2DObject(objH)
|
||||
{
|
||||
char* typeID = "{0000000000000-0000-0000-000000000002}";
|
||||
set_hobj_attr_value(id_TypeID, objH, typeID);
|
||||
|
||||
PostCreate();
|
||||
|
||||
}
|
||||
|
||||
sgCLine* sgCLine::Create(sgFloat pX1, sgFloat pY1, sgFloat pZ1,
|
||||
sgFloat pX2, sgFloat pY2, sgFloat pZ2)
|
||||
{
|
||||
SG_LINE gp;
|
||||
gp.p1.x = pX1;
|
||||
gp.p1.y = pY1;
|
||||
gp.p1.z = pZ1;
|
||||
gp.p2.x = pX2;
|
||||
gp.p2.y = pY2;
|
||||
gp.p2.z = pZ2;
|
||||
|
||||
if (sgSpaceMath::PointsDistance(gp.p1,gp.p2)<eps_d)
|
||||
{
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_ZERO_LENGTH;
|
||||
return NULL; //
|
||||
}
|
||||
|
||||
global_sg_error = SG_ER_SUCCESS;
|
||||
|
||||
sgCLine* newLn=new sgCLine;
|
||||
SetObjectHandle(newLn,create_simple_obj_loc(OLINE, &gp));
|
||||
((lpOBJ)(GetObjectHandle(newLn)))->extendedClass = newLn;
|
||||
|
||||
char* typeID = "{0000000000000-0000-0000-000000000002}";
|
||||
set_hobj_attr_value(id_TypeID, GetObjectHandle(newLn), typeID);
|
||||
|
||||
newLn->PostCreate();
|
||||
|
||||
return newLn;
|
||||
}
|
||||
|
||||
const SG_LINE* sgCLine::GetGeometry() const
|
||||
{
|
||||
lpOBJ pobj = (lpOBJ)(GetObjectHandle(this));
|
||||
return static_cast<SG_LINE*>((void*)(pobj->geo_data));
|
||||
}
|
||||
|
||||
bool sgCLine::IsClosed() const {return false;}
|
||||
bool sgCLine::IsPlane(SG_VECTOR*,sgFloat*) const {return false;}
|
||||
bool sgCLine::IsLinear() const {return true;}
|
||||
bool sgCLine::IsSelfIntersecting() const {return false;}
|
||||
@@ -0,0 +1,42 @@
|
||||
#include "..//Core//sg.h"
|
||||
|
||||
sgCPoint::sgCPoint():sgCObject()
|
||||
{
|
||||
}
|
||||
|
||||
sgCPoint::~sgCPoint()
|
||||
{
|
||||
}
|
||||
|
||||
sgCPoint::sgCPoint(SG_OBJ_HANDLE objH):sgCObject(objH)
|
||||
{
|
||||
char* typeID = "{0000000000000-0000-0000-000000000001}";
|
||||
set_hobj_attr_value(id_TypeID, objH, typeID);
|
||||
|
||||
PostCreate();
|
||||
|
||||
}
|
||||
sgCPoint* sgCPoint::Create(sgFloat pX, sgFloat pY, sgFloat pZ)
|
||||
{
|
||||
SG_POINT gp;
|
||||
gp.x = pX;
|
||||
gp.y = pY;
|
||||
gp.z = pZ;
|
||||
|
||||
sgCPoint* newPnt=new sgCPoint;
|
||||
SetObjectHandle(newPnt, create_simple_obj_loc(OPOINT, &gp));
|
||||
((lpOBJ)(GetObjectHandle(newPnt)))->extendedClass = newPnt;
|
||||
|
||||
char* typeID = "{0000000000000-0000-0000-000000000001}";
|
||||
set_hobj_attr_value(id_TypeID, GetObjectHandle(newPnt), typeID);
|
||||
|
||||
newPnt->PostCreate();
|
||||
|
||||
return newPnt;
|
||||
}
|
||||
|
||||
const SG_POINT* sgCPoint::GetGeometry() const
|
||||
{
|
||||
lpOBJ pobj = (lpOBJ)(GetObjectHandle(this));
|
||||
return static_cast<SG_POINT*>((void*)(pobj->geo_data));
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
#include "..//Core//sg.h"
|
||||
|
||||
sgCSphere::sgCSphere():sgC3DObject()
|
||||
{
|
||||
}
|
||||
|
||||
sgCSphere::~sgCSphere()
|
||||
{
|
||||
}
|
||||
|
||||
sgCSphere::sgCSphere(SG_OBJ_HANDLE objH):sgC3DObject(objH)
|
||||
{
|
||||
char* typeID = "{0000000000000-0000-0002-000000000009}";
|
||||
set_hobj_attr_value(id_TypeID, objH, typeID);
|
||||
|
||||
PostCreate();
|
||||
|
||||
}
|
||||
|
||||
sgCSphere* sgCSphere::Create(sgFloat rad, short merid, short parall)
|
||||
{
|
||||
if (rad<eps_d ||
|
||||
merid<2 ||
|
||||
parall<2)
|
||||
return NULL;
|
||||
|
||||
sgFloat par[3];
|
||||
par[0] = rad;
|
||||
par[1] = (sgFloat)merid;
|
||||
par[2] = (sgFloat)parall;
|
||||
|
||||
hOBJ hO = create_primitive_obj(SPHERE, par);
|
||||
assert(hO);
|
||||
|
||||
sgCSphere* newSp=new sgCSphere(hO);
|
||||
|
||||
newSp->PostCreate();
|
||||
|
||||
return newSp;
|
||||
}
|
||||
|
||||
|
||||
void sgCSphere::GetGeometry(SG_SPHERE& res) const
|
||||
{
|
||||
lpOBJ obj = static_cast<lpOBJ>(GetObjectHandle(this));
|
||||
assert(obj);
|
||||
|
||||
lpGEO_BREP geo = (lpGEO_BREP)(obj->geo_data);
|
||||
assert(geo);
|
||||
|
||||
LNP lnp;
|
||||
|
||||
if ( !read_elem(&vd_brep,geo->num,&lnp) )
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
|
||||
lpCSG csg = static_cast<lpCSG>(lnp.hcsg);
|
||||
assert(csg);
|
||||
|
||||
sgFloat* pars = (sgFloat*)malloc(csg->size);
|
||||
|
||||
memcpy(pars, csg->data, csg->size);
|
||||
|
||||
res.Radius = pars[0];
|
||||
res.MeridiansCount = static_cast<short>(pars[1]);
|
||||
res.ParallelsCount = static_cast<short>(pars[2]);
|
||||
|
||||
free(pars);
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
#include "..//Core//sg.h"
|
||||
|
||||
sgCSphericBand::sgCSphericBand():sgC3DObject()
|
||||
{
|
||||
}
|
||||
|
||||
sgCSphericBand::~sgCSphericBand()
|
||||
{
|
||||
}
|
||||
|
||||
sgCSphericBand::sgCSphericBand(SG_OBJ_HANDLE objH):sgC3DObject(objH)
|
||||
{
|
||||
char* typeID = "{0000000000000-0000-0009-000000000009}";
|
||||
set_hobj_attr_value(id_TypeID, objH, typeID);
|
||||
|
||||
PostCreate();
|
||||
|
||||
}
|
||||
|
||||
sgCSphericBand* sgCSphericBand::Create(sgFloat radius, sgFloat beg_koef,
|
||||
sgFloat end_koef,
|
||||
short merid_cnt)
|
||||
{
|
||||
if (radius<eps_d ||
|
||||
merid_cnt<2 ||
|
||||
beg_koef>1 ||
|
||||
beg_koef<-1 ||
|
||||
end_koef>1 ||
|
||||
end_koef<-1 ||
|
||||
end_koef<=beg_koef)
|
||||
return NULL;
|
||||
|
||||
sgFloat par[5];
|
||||
|
||||
par[0] = radius;
|
||||
par[1] = beg_koef;
|
||||
par[2] = end_koef;
|
||||
par[3] = 0.0;
|
||||
par[4] = (sgFloat)merid_cnt;
|
||||
|
||||
|
||||
hOBJ hO = create_primitive_obj(SPHERIC_BAND, par);
|
||||
assert(hO);
|
||||
|
||||
sgCSphericBand* newSp=new sgCSphericBand(hO);
|
||||
|
||||
newSp->PostCreate();
|
||||
|
||||
return newSp;
|
||||
}
|
||||
|
||||
|
||||
void sgCSphericBand::GetGeometry(SG_SPHERIC_BAND& res) const
|
||||
{
|
||||
lpOBJ obj = static_cast<lpOBJ>(GetObjectHandle(this));
|
||||
assert(obj);
|
||||
|
||||
lpGEO_BREP geo = (lpGEO_BREP)(obj->geo_data);
|
||||
assert(geo);
|
||||
|
||||
LNP lnp;
|
||||
|
||||
if ( !read_elem(&vd_brep,geo->num,&lnp) )
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
|
||||
lpCSG csg = static_cast<lpCSG>(lnp.hcsg);
|
||||
assert(csg);
|
||||
|
||||
sgFloat* pars = (sgFloat*)malloc(csg->size);
|
||||
|
||||
memcpy(pars, csg->data, csg->size);
|
||||
|
||||
res.Radius = pars[0];
|
||||
res.BeginCoef = pars[1];
|
||||
res.EndCoef = pars[2];
|
||||
res.MeridiansCount = static_cast<short>(pars[4]);
|
||||
|
||||
free(pars);
|
||||
}
|
||||
@@ -0,0 +1,523 @@
|
||||
#include "..//Core//sg.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
static void ExtractPointsAndKnotsFromSplineDAT(SPLY_DAT* splD,
|
||||
SG_POINT*& pnts,
|
||||
int& pnts_cnt,
|
||||
SG_POINT*& knts,
|
||||
int& knts_cnt)
|
||||
{
|
||||
|
||||
if (pnts)
|
||||
{
|
||||
delete [] pnts;
|
||||
pnts = NULL;
|
||||
pnts_cnt=0;
|
||||
}
|
||||
if (knts)
|
||||
{
|
||||
delete [] knts;
|
||||
knts = NULL;
|
||||
knts_cnt=0;
|
||||
}
|
||||
|
||||
std::vector<SG_POINT> Pnt_vector;
|
||||
Pnt_vector.reserve(50);
|
||||
|
||||
BOOL knot;
|
||||
D_POINT pnt;
|
||||
SG_POINT sPnt;
|
||||
|
||||
get_first_sply_point(splD, 0., FALSE, &pnt);
|
||||
memcpy(&sPnt,&pnt,sizeof(SG_POINT));
|
||||
Pnt_vector.push_back(sPnt);
|
||||
while( get_next_sply_point_and_knot(splD, &pnt, &knot) )
|
||||
{
|
||||
memcpy(&sPnt,&pnt,sizeof(SG_POINT));
|
||||
Pnt_vector.push_back(sPnt);
|
||||
}
|
||||
|
||||
pnts_cnt = Pnt_vector.size();
|
||||
|
||||
pnts = new SG_POINT[pnts_cnt];
|
||||
|
||||
memcpy(pnts, &Pnt_vector[0], sizeof(SG_POINT)*pnts_cnt);
|
||||
|
||||
Pnt_vector.clear();
|
||||
Pnt_vector.reserve(30);
|
||||
|
||||
short i;
|
||||
sgFloat w;
|
||||
|
||||
if( splD->sdtype & SPL_APPR )
|
||||
{ // .
|
||||
Create_3D_From_4D( &splD->P[0], (sgFloat *)&pnt, &w );
|
||||
memcpy(&sPnt,&pnt,sizeof(SG_POINT));
|
||||
Pnt_vector.push_back(sPnt);
|
||||
for( i=0; i<splD->nump-1; i++)
|
||||
{
|
||||
Create_3D_From_4D( &splD->P[i+1], (sgFloat *)&pnt, &w );
|
||||
memcpy(&sPnt,&pnt,sizeof(SG_POINT));
|
||||
Pnt_vector.push_back(sPnt);
|
||||
}
|
||||
}
|
||||
|
||||
knts_cnt = Pnt_vector.size();
|
||||
|
||||
knts = new SG_POINT[knts_cnt];
|
||||
|
||||
memcpy(knts, &Pnt_vector[0], sizeof(SG_POINT)*knts_cnt);
|
||||
|
||||
Pnt_vector.clear();
|
||||
}
|
||||
|
||||
SG_SPLINE::SG_SPLINE()
|
||||
{
|
||||
m_handle = NULL;
|
||||
m_points = NULL;
|
||||
m_points_count=0;
|
||||
m_knots = NULL;
|
||||
m_knots_count=0;
|
||||
}
|
||||
|
||||
SG_SPLINE::SG_SPLINE(void* SplObjHndl)
|
||||
{
|
||||
m_handle = NULL;
|
||||
m_points = NULL;
|
||||
m_points_count=0;
|
||||
m_knots = NULL;
|
||||
m_knots_count=0;
|
||||
|
||||
assert(SplObjHndl);
|
||||
|
||||
lpOBJ pobj = (lpOBJ)SplObjHndl;
|
||||
|
||||
m_handle = SGMalloc(sizeof(SPLY_DAT));
|
||||
//----------------------------------->
|
||||
OBJ oldobj;
|
||||
GEO_SPLINE geo_sply;
|
||||
get_simple_obj(SplObjHndl, &oldobj, &geo_sply);
|
||||
|
||||
short type_s = (geo_sply.type & SPLY_APPR) ? SPL_APPR : SPL_INT;;
|
||||
//
|
||||
if(!init_sply_dat(SPL_NEW, geo_sply.degree, type_s, (SPLY_DAT*)m_handle))
|
||||
{
|
||||
assert(0);
|
||||
global_sg_error = SG_ER_INTERNAL;
|
||||
return;
|
||||
}
|
||||
|
||||
unpack_geo_sply((lpGEO_SPLINE)(pobj->geo_data), (SPLY_DAT*)m_handle);
|
||||
|
||||
ExtractPointsAndKnotsFromSplineDAT((SPLY_DAT*)m_handle,
|
||||
m_points,m_points_count, m_knots,m_knots_count );
|
||||
}
|
||||
|
||||
void SG_SPLINE::Recalc()
|
||||
{
|
||||
assert(m_handle);
|
||||
ExtractPointsAndKnotsFromSplineDAT((SPLY_DAT*)m_handle,
|
||||
m_points,m_points_count, m_knots,m_knots_count );
|
||||
}
|
||||
|
||||
SG_SPLINE::~SG_SPLINE()
|
||||
{
|
||||
assert(m_handle);
|
||||
|
||||
lpSPLY_DAT spl = (lpSPLY_DAT)m_handle;
|
||||
free_sply_dat(spl);
|
||||
SGFree(m_handle);
|
||||
|
||||
if (m_points)
|
||||
{
|
||||
delete [] m_points;
|
||||
m_points = NULL;
|
||||
m_points_count=0;
|
||||
}
|
||||
if (m_knots)
|
||||
{
|
||||
delete [] m_knots;
|
||||
m_knots = NULL;
|
||||
m_knots_count=0;
|
||||
}
|
||||
}
|
||||
|
||||
SG_SPLINE* SG_SPLINE::Create()
|
||||
{
|
||||
SG_SPLINE* res = new SG_SPLINE();
|
||||
|
||||
res->m_handle = SGMalloc(sizeof(SPLY_DAT));
|
||||
//----------------------------------->
|
||||
short degree = 2;
|
||||
short type_s = SPL_APPR; //
|
||||
//----------------------------------->
|
||||
if(!init_sply_dat(SPL_NEW, degree, type_s, (SPLY_DAT*)res->m_handle))
|
||||
{
|
||||
global_sg_error = SG_ER_INTERNAL;
|
||||
return NULL;
|
||||
}
|
||||
global_sg_error = SG_ER_SUCCESS;
|
||||
return res;
|
||||
}
|
||||
|
||||
void SG_SPLINE::Delete(SG_SPLINE* splG)
|
||||
{
|
||||
assert(splG);
|
||||
delete splG;
|
||||
}
|
||||
|
||||
bool SG_SPLINE::AddKnot(const SG_POINT& pnt, int nmbr)
|
||||
{
|
||||
if (nmbr>=MAX_POINT_ON_SPLINE)
|
||||
return false;
|
||||
|
||||
spl_work=CRE_SPL;
|
||||
D_POINT pnt_old;
|
||||
memcpy(&pnt_old, &pnt, sizeof(SG_POINT));
|
||||
if (nmbr<0 || nmbr>m_knots_count)
|
||||
{
|
||||
assert(0);
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_UNKNOWN;
|
||||
return false;
|
||||
}
|
||||
|
||||
add_sply_point((SPLY_DAT*)m_handle, &pnt_old, nmbr);
|
||||
|
||||
ExtractPointsAndKnotsFromSplineDAT((SPLY_DAT*)m_handle,
|
||||
m_points,m_points_count, m_knots,m_knots_count );
|
||||
|
||||
global_sg_error = SG_ER_SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SG_SPLINE::MoveKnot(int nmbr, const SG_POINT& pnt)
|
||||
{
|
||||
D_POINT pnt_old;
|
||||
memcpy(&pnt_old, &pnt, sizeof(SG_POINT));
|
||||
if (nmbr<0 || nmbr>m_knots_count)
|
||||
{
|
||||
assert(0);
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_UNKNOWN;
|
||||
return false;
|
||||
}
|
||||
|
||||
move_sply_point((SPLY_DAT*)m_handle, nmbr, &pnt_old);
|
||||
|
||||
ExtractPointsAndKnotsFromSplineDAT((SPLY_DAT*)m_handle,
|
||||
m_points,m_points_count, m_knots,m_knots_count );
|
||||
global_sg_error = SG_ER_SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SG_SPLINE::DeleteKnot(int nmbr)
|
||||
{
|
||||
spl_work=CRE_SPL;
|
||||
if (nmbr<0 || nmbr>m_knots_count)
|
||||
{
|
||||
assert(0);
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_UNKNOWN;
|
||||
return false;
|
||||
}
|
||||
|
||||
delete_sply_point((SPLY_DAT*)m_handle, (short)nmbr);
|
||||
|
||||
ExtractPointsAndKnotsFromSplineDAT((SPLY_DAT*)m_handle,
|
||||
m_points,m_points_count, m_knots,m_knots_count );
|
||||
global_sg_error = SG_ER_SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SG_SPLINE::IsClosed() const
|
||||
{
|
||||
if (((SPLY_DAT*)m_handle)->sdtype & SPL_CLOSE)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SG_SPLINE::Close()
|
||||
{
|
||||
if (!close_sply((SPLY_DAT*)m_handle))
|
||||
{
|
||||
global_sg_error = SG_ER_INTERNAL;
|
||||
return false;
|
||||
}
|
||||
ExtractPointsAndKnotsFromSplineDAT((SPLY_DAT*)m_handle,
|
||||
m_points,m_points_count, m_knots,m_knots_count );
|
||||
global_sg_error = SG_ER_SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SG_SPLINE::UnClose(int interv)
|
||||
{
|
||||
if(!break_close_sply((SPLY_DAT*)m_handle,(short)interv))
|
||||
{
|
||||
global_sg_error = SG_ER_INTERNAL;
|
||||
return false;
|
||||
}
|
||||
ExtractPointsAndKnotsFromSplineDAT((SPLY_DAT*)m_handle,
|
||||
m_points,m_points_count, m_knots,m_knots_count );
|
||||
global_sg_error = SG_ER_SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
const SG_POINT* SG_SPLINE::GetPoints() const
|
||||
{
|
||||
return m_points;
|
||||
}
|
||||
|
||||
int SG_SPLINE::GetPointsCount() const
|
||||
{
|
||||
return m_points_count;
|
||||
}
|
||||
|
||||
const SG_POINT* SG_SPLINE::GetKnots() const
|
||||
{
|
||||
return m_knots;
|
||||
}
|
||||
|
||||
int SG_SPLINE::GetKnotsCount() const
|
||||
{
|
||||
return m_knots_count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static bool is_spline_on_one_line(const SG_SPLINE* splG)
|
||||
{
|
||||
const SG_POINT* pnts = splG->GetKnots();
|
||||
const int pntsCnt = splG->GetKnotsCount();
|
||||
|
||||
if (pntsCnt<=2)
|
||||
return true;
|
||||
|
||||
SG_POINT p1 = pnts[0];
|
||||
SG_POINT p2 = pnts[1];
|
||||
|
||||
for (int i=2;i<pntsCnt;i++)
|
||||
if (!sgSpaceMath::IsPointsOnOneLine(p1,p2,pnts[i]))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
sgCSpline::sgCSpline():sgC2DObject()
|
||||
{
|
||||
m_spline_geo = NULL;
|
||||
}
|
||||
|
||||
|
||||
bool sgCSpline::ApplyTempMatrix()
|
||||
{
|
||||
if (!sgCObject::ApplyTempMatrix())
|
||||
return false;
|
||||
if (m_spline_geo)
|
||||
{
|
||||
delete m_spline_geo;
|
||||
m_spline_geo = NULL;
|
||||
m_spline_geo = new SG_SPLINE(GetObjectHandle(this));
|
||||
|
||||
lpOBJ obj = (lpOBJ)GetObjectHandle(this);
|
||||
if (obj->status & ST_FLAT)
|
||||
{
|
||||
D_PLANE plane;
|
||||
|
||||
// ROBLOX change
|
||||
//#if (SG_CURRENT_PLATFORM==SG_PLATFORM_IOS)
|
||||
sgFloat savingEpsD = eps_d;
|
||||
eps_d *=100.0; // fix for sgFloat = float (not double )
|
||||
//#endif
|
||||
if (set_flat_on_path(GetObjectHandle(this), &plane))
|
||||
{
|
||||
obj->status |= ST_FLAT;
|
||||
memcpy(&m_plane_normal,&plane.v,sizeof(D_POINT));
|
||||
m_plane_D =plane.d;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(0);
|
||||
obj->status &= ~ST_FLAT;
|
||||
}
|
||||
// ROBLOX change
|
||||
//#if (SG_CURRENT_PLATFORM==SG_PLATFORM_IOS)
|
||||
eps_d =savingEpsD;
|
||||
//#endif
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
sgCSpline::~sgCSpline()
|
||||
{
|
||||
if (m_spline_geo)
|
||||
delete m_spline_geo;
|
||||
}
|
||||
|
||||
sgCSpline::sgCSpline(SG_OBJ_HANDLE objH):sgC2DObject(objH)
|
||||
{
|
||||
char* typeID = "{0000000000000-0000-0000-000000000005}";
|
||||
set_hobj_attr_value(id_TypeID, objH, typeID);
|
||||
|
||||
m_spline_geo = new SG_SPLINE(objH);
|
||||
|
||||
lpOBJ obj = (lpOBJ)objH;
|
||||
|
||||
/*if (is_spline_on_one_line(m_spline_geo))
|
||||
{
|
||||
obj->status |= ST_ON_LINE;
|
||||
obj->status &= ~ST_FLAT;
|
||||
}
|
||||
else
|
||||
{
|
||||
D_PLANE plane;
|
||||
if (set_flat_on_path(m_object_handle, &plane))
|
||||
{
|
||||
obj->status |= ST_FLAT;
|
||||
memcpy(&m_plane_normal,&plane.v,sizeof(D_POINT));
|
||||
m_plane_D =plane.d;
|
||||
}
|
||||
else
|
||||
obj->status &= ~ST_FLAT;
|
||||
}*/
|
||||
if (obj->status & ST_FLAT)
|
||||
{
|
||||
D_PLANE plane;
|
||||
if (set_flat_on_path(objH, &plane))
|
||||
{
|
||||
obj->status |= ST_FLAT;
|
||||
memcpy(&m_plane_normal,&plane.v,sizeof(D_POINT));
|
||||
m_plane_D =plane.d;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(0);
|
||||
obj->status &= ~ST_FLAT;
|
||||
}
|
||||
}
|
||||
|
||||
PostCreate();
|
||||
|
||||
}
|
||||
|
||||
sgCSpline* sgCSpline::Create(const SG_SPLINE& splG)
|
||||
{
|
||||
GEO_SPLINE geo_sply;
|
||||
//OSTATUS status;
|
||||
|
||||
spl_work=CRE_SPL;
|
||||
|
||||
if(!create_geo_sply((lpSPLY_DAT)splG.m_handle, &geo_sply))
|
||||
{
|
||||
assert(0);
|
||||
global_sg_error = SG_ER_INTERNAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//
|
||||
//status = ST_CLOSE;//(spl.sdtype & SPL_CLOSE) ? ST_CLOSE : 0;
|
||||
//free_sply_dat(spl);
|
||||
|
||||
sgCSpline* newSpl=new sgCSpline;
|
||||
SetObjectHandle(newSpl,create_simple_obj_loc(OSPLINE, &geo_sply));
|
||||
((lpOBJ)(GetObjectHandle(newSpl)))->extendedClass = newSpl;
|
||||
|
||||
lpOBJ obj = (lpOBJ)GetObjectHandle(newSpl);
|
||||
obj->status &= ~(ST_CLOSE | ST_FLAT | ST_SIMPLE | ST_ON_LINE);
|
||||
|
||||
OSTATUS status;
|
||||
status = (OSTATUS)((((lpSPLY_DAT)splG.m_handle)->sdtype & SPL_CLOSE) ? ST_CLOSE : 0);
|
||||
obj->status |= status;
|
||||
|
||||
if (is_spline_on_one_line(&splG))
|
||||
{
|
||||
obj->status |= ST_ON_LINE;
|
||||
obj->status &= ~ST_FLAT;
|
||||
}
|
||||
else
|
||||
{
|
||||
D_PLANE plane;
|
||||
if (set_flat_on_path(GetObjectHandle(newSpl), &plane))
|
||||
{
|
||||
obj->status |= ST_FLAT;
|
||||
memcpy(&newSpl->m_plane_normal,&plane.v,sizeof(D_POINT));
|
||||
newSpl->m_plane_D =plane.d;
|
||||
}
|
||||
else
|
||||
obj->status &= ~ST_FLAT;
|
||||
}
|
||||
|
||||
OSCAN_COD cod;
|
||||
if( (cod = test_self_cross_path(GetObjectHandle(newSpl), NULL)) == OSFALSE )
|
||||
{
|
||||
sgCObject::DeleteObject(newSpl);
|
||||
assert(0);
|
||||
global_sg_error = SG_ER_INTERNAL;
|
||||
return NULL;
|
||||
}
|
||||
if( cod == OSTRUE ){
|
||||
obj->status |= ST_SIMPLE;
|
||||
}
|
||||
|
||||
newSpl->m_spline_geo = new SG_SPLINE(GetObjectHandle(newSpl));
|
||||
|
||||
char* typeID = "{0000000000000-0000-0000-000000000005}";
|
||||
set_hobj_attr_value(id_TypeID, GetObjectHandle(newSpl), typeID);
|
||||
|
||||
newSpl->PostCreate();
|
||||
|
||||
global_sg_error = SG_ER_SUCCESS;
|
||||
|
||||
return newSpl;
|
||||
}
|
||||
|
||||
const SG_SPLINE* sgCSpline::GetGeometry() const
|
||||
{
|
||||
return m_spline_geo;
|
||||
}
|
||||
|
||||
bool sgCSpline::IsClosed() const
|
||||
{
|
||||
if (!m_spline_geo)
|
||||
return false;
|
||||
return m_spline_geo->IsClosed();
|
||||
}
|
||||
|
||||
bool sgCSpline::IsPlane(SG_VECTOR* plN,sgFloat* plD) const
|
||||
{
|
||||
if (((lpOBJ)GetObjectHandle(this))->status & ST_FLAT)
|
||||
{
|
||||
if (plN)
|
||||
*plN = m_plane_normal;
|
||||
if (plD)
|
||||
*plD = m_plane_D;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool sgCSpline::IsLinear() const
|
||||
{
|
||||
if (((lpOBJ)GetObjectHandle(this))->status & ST_ON_LINE)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool sgCSpline::IsSelfIntersecting() const
|
||||
{
|
||||
if (((lpOBJ)GetObjectHandle(this))->status & ST_SIMPLE)
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,812 @@
|
||||
#include "..//CORE//sg.h"
|
||||
|
||||
sgCObject* sgSurfaces::Face(const sgC2DObject& outContour,
|
||||
const sgC2DObject** holes,
|
||||
int holes_count)
|
||||
{
|
||||
sgC2DObject* f_o = const_cast<sgC2DObject*>(&outContour);
|
||||
|
||||
hOBJ* select_list_before = NULL;
|
||||
int select_list_before_size = 0;
|
||||
if (selected.num>0)
|
||||
{
|
||||
select_list_before = (hOBJ*)SGMalloc((selected.num)*sizeof(hOBJ));
|
||||
select_list_before_size = selected.num;
|
||||
hOBJ tmp_hobj = selected.hhead;
|
||||
hOBJ tmp_hobj_next;
|
||||
int tmpI = 0;
|
||||
while(tmp_hobj)
|
||||
{
|
||||
select_list_before[tmpI] = tmp_hobj;
|
||||
get_next_item_z(SEL_LIST, tmp_hobj, &tmp_hobj_next);
|
||||
((lpOBJ)tmp_hobj)->extendedClass->Select(false);
|
||||
tmpI++;
|
||||
tmp_hobj = tmp_hobj_next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
short* object_statuses = (short*)SGMalloc((holes_count+1)*sizeof(short));
|
||||
object_statuses[0] = ((lpOBJ)GetObjectHandle(f_o))->status;
|
||||
|
||||
hOBJ* otvs_handls = NULL;
|
||||
if (holes_count>0)
|
||||
otvs_handls = (hOBJ*)SGMalloc(sizeof(hOBJ)*holes_count);
|
||||
for (int i=0;i<holes_count;i++)
|
||||
{
|
||||
otvs_handls[i] = GetObjectHandle(holes[i]);
|
||||
object_statuses[i+1] = ((lpOBJ)otvs_handls[i])->status;
|
||||
}
|
||||
|
||||
if (test_correct_paths_array_for_face_command(GetObjectHandle(f_o),
|
||||
otvs_handls,holes_count)!=TCPR_SUCCESS)
|
||||
{
|
||||
SGFree(otvs_handls);
|
||||
|
||||
((lpOBJ)GetObjectHandle(f_o))->status = object_statuses[0];
|
||||
for (int i=0;i<holes_count;i++)
|
||||
{
|
||||
((lpOBJ)otvs_handls[i])->status = object_statuses[i+1];
|
||||
}
|
||||
SGFree(object_statuses);
|
||||
|
||||
for (int i=0;i<select_list_before_size;i++)
|
||||
((lpOBJ)select_list_before[i])->extendedClass->Select(true);
|
||||
SGFree(select_list_before);
|
||||
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_CONFLICT_BEETWEEN_ARGS;
|
||||
return NULL;
|
||||
}
|
||||
if (otvs_handls)
|
||||
SGFree(otvs_handls);
|
||||
|
||||
LISTH listh_otv;
|
||||
init_listh(&listh_otv);
|
||||
|
||||
hOBJ tmpHndl=NULL;
|
||||
lpOBJ obj = NULL;
|
||||
|
||||
tmpHndl = GetObjectHandle(f_o);
|
||||
|
||||
attach_item_tail_z(SEL_LIST,&listh_otv, tmpHndl);
|
||||
|
||||
for (int i=0;i<holes_count;i++)
|
||||
{
|
||||
tmpHndl = GetObjectHandle(holes[i]);
|
||||
|
||||
attach_item_tail_z(SEL_LIST,&listh_otv, tmpHndl);
|
||||
}
|
||||
|
||||
hOBJ ob_new;
|
||||
if (!faced_mesh(&listh_otv, &ob_new))
|
||||
{
|
||||
((lpOBJ)GetObjectHandle(f_o))->status = object_statuses[0];
|
||||
for (int i=0;i<holes_count;i++)
|
||||
{
|
||||
((lpOBJ)GetObjectHandle(holes[i]))->status = object_statuses[i+1];
|
||||
}
|
||||
SGFree(object_statuses);
|
||||
|
||||
for (int i=0;i<select_list_before_size;i++)
|
||||
((lpOBJ)select_list_before[i])->extendedClass->Select(true);
|
||||
SGFree(select_list_before);
|
||||
|
||||
global_sg_error = SG_ER_INTERNAL;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (int i=0;i<holes_count;i++)
|
||||
detach_item_z(SEL_LIST,&listh_otv, GetObjectHandle(holes[i]));
|
||||
detach_item_z(SEL_LIST,&listh_otv, GetObjectHandle(f_o));
|
||||
|
||||
((lpOBJ)GetObjectHandle(f_o))->status = object_statuses[0];
|
||||
for (int i=0;i<holes_count;i++)
|
||||
{
|
||||
((lpOBJ)GetObjectHandle(holes[i]))->status = object_statuses[i+1];
|
||||
}
|
||||
SGFree(object_statuses);
|
||||
|
||||
for (int i=0;i<select_list_before_size;i++)
|
||||
((lpOBJ)select_list_before[i])->extendedClass->Select(true);
|
||||
SGFree(select_list_before);
|
||||
|
||||
global_sg_error = SG_ER_SUCCESS;
|
||||
|
||||
return ObjectFromHandle(ob_new);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static bool sort_curves_for_coons_command(const sgC2DObject& firstSide,
|
||||
const sgC2DObject& secondSide,
|
||||
const sgC2DObject& thirdSide,
|
||||
const sgC2DObject* fourthSide,
|
||||
hOBJ& fir_hObj,
|
||||
hOBJ& sec_hObj,
|
||||
hOBJ& thi_hObj,
|
||||
hOBJ& fou_hObj,
|
||||
bool& need_reverse_fir,
|
||||
bool& need_reverse_sec,
|
||||
bool& need_reverse_thi,
|
||||
bool& need_reverse_fou)
|
||||
{
|
||||
typedef struct
|
||||
{
|
||||
D_POINT begin_of_curve;
|
||||
D_POINT end_of_curve;
|
||||
} BEGIN_AND_END;
|
||||
|
||||
BEGIN_AND_END begins_and_ends[4];
|
||||
|
||||
hOBJ obj_handles[4];
|
||||
obj_handles[0] = GetObjectHandle(&firstSide);
|
||||
obj_handles[1] = GetObjectHandle(&secondSide);
|
||||
obj_handles[2] = GetObjectHandle(&thirdSide);
|
||||
obj_handles[3] = (fourthSide)?GetObjectHandle(fourthSide):NULL;
|
||||
|
||||
int i;
|
||||
for (i=0;i<4;i++)
|
||||
{
|
||||
if (!obj_handles[i]) continue;
|
||||
if (!init_get_point_on_path(obj_handles[i], NULL)) return false;
|
||||
if (!get_point_on_path(0., &(begins_and_ends[i].begin_of_curve))) return false;
|
||||
if (!get_point_on_path(1., &(begins_and_ends[i].end_of_curve))) return false;
|
||||
term_get_point_on_path();
|
||||
}
|
||||
|
||||
fir_hObj = obj_handles[0];
|
||||
need_reverse_fir = false;
|
||||
|
||||
D_POINT curStart,curFinish;
|
||||
|
||||
curStart = begins_and_ends[0].begin_of_curve;
|
||||
curFinish = begins_and_ends[0].end_of_curve;
|
||||
|
||||
int sec_curve_index=-1;
|
||||
for (i=1;i<4;i++)
|
||||
{
|
||||
if (!obj_handles[i]) continue;
|
||||
if (dpoint_eq(&curFinish, &(begins_and_ends[i].begin_of_curve), eps_d))
|
||||
{
|
||||
sec_hObj = obj_handles[i];
|
||||
need_reverse_sec = false;
|
||||
curFinish = begins_and_ends[i].end_of_curve;
|
||||
sec_curve_index = i;
|
||||
goto searchThird;
|
||||
}
|
||||
if (dpoint_eq(&curFinish, &(begins_and_ends[i].end_of_curve), eps_d))
|
||||
{
|
||||
sec_hObj = obj_handles[i];
|
||||
need_reverse_sec = true;
|
||||
curFinish = begins_and_ends[i].begin_of_curve;
|
||||
sec_curve_index = i;
|
||||
goto searchThird;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
searchThird:
|
||||
|
||||
int third_curve_index=-1;
|
||||
|
||||
for (i=1;i<4;i++)
|
||||
{
|
||||
if (!obj_handles[i] || i==sec_curve_index) continue;
|
||||
if (dpoint_eq(&curFinish, &(begins_and_ends[i].begin_of_curve), eps_d))
|
||||
{
|
||||
thi_hObj = obj_handles[i];
|
||||
need_reverse_thi = false;
|
||||
curFinish = begins_and_ends[i].end_of_curve;
|
||||
third_curve_index = i;
|
||||
goto searchFourth;
|
||||
}
|
||||
if (dpoint_eq(&curFinish, &(begins_and_ends[i].end_of_curve), eps_d))
|
||||
{
|
||||
thi_hObj = obj_handles[i];
|
||||
need_reverse_thi = true;
|
||||
curFinish = begins_and_ends[i].begin_of_curve;
|
||||
third_curve_index = i;
|
||||
goto searchFourth;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
searchFourth:
|
||||
|
||||
if (fourthSide==NULL)
|
||||
{
|
||||
if (!dpoint_eq(&curFinish, &(begins_and_ends[0].begin_of_curve), eps_d))
|
||||
{
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
fou_hObj = NULL;
|
||||
need_reverse_fou = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
for (i=1;i<4;i++)
|
||||
{
|
||||
if (!obj_handles[i] || i==sec_curve_index || i==third_curve_index) continue;
|
||||
if (dpoint_eq(&curFinish, &(begins_and_ends[i].begin_of_curve), eps_d))
|
||||
{
|
||||
fou_hObj = obj_handles[i];
|
||||
need_reverse_fou = false;
|
||||
curFinish = begins_and_ends[i].end_of_curve;
|
||||
if (!dpoint_eq(&curFinish, &(begins_and_ends[0].begin_of_curve), eps_d))
|
||||
{
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (dpoint_eq(&curFinish, &(begins_and_ends[i].end_of_curve), eps_d))
|
||||
{
|
||||
fou_hObj = obj_handles[i];
|
||||
need_reverse_fou = true;
|
||||
curFinish = begins_and_ends[i].begin_of_curve;
|
||||
if (!dpoint_eq(&curFinish, &(begins_and_ends[0].begin_of_curve), eps_d))
|
||||
{
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
sgCObject* sgSurfaces::Coons(const sgC2DObject& firstSide,
|
||||
const sgC2DObject& secondSide,
|
||||
const sgC2DObject& thirdSide,
|
||||
const sgC2DObject* fourthSide,
|
||||
short uSegments,
|
||||
short vSegments,
|
||||
short uVisEdges,
|
||||
short vVisEdges)
|
||||
{
|
||||
|
||||
if (firstSide.IsClosed() ||
|
||||
secondSide.IsClosed() ||
|
||||
thirdSide.IsClosed() ||
|
||||
(fourthSide && fourthSide->IsClosed()))
|
||||
{
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_UNKNOWN;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (firstSide.IsSelfIntersecting() ||
|
||||
secondSide.IsSelfIntersecting() ||
|
||||
thirdSide.IsSelfIntersecting() ||
|
||||
(fourthSide && fourthSide->IsSelfIntersecting()))
|
||||
{
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_UNKNOWN;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hOBJ hnew;
|
||||
hOBJ hobj[4];
|
||||
bool reverse[4];
|
||||
VDIM vdim[4];
|
||||
|
||||
if (!sort_curves_for_coons_command(firstSide,secondSide,thirdSide,fourthSide,
|
||||
hobj[0],hobj[1],hobj[2],hobj[3],
|
||||
reverse[0],reverse[1],reverse[2],reverse[3]))
|
||||
{
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_CONFLICT_BEETWEEN_ARGS;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (fourthSide == NULL) { // u2
|
||||
hobj[3] = hobj[2];
|
||||
hobj[2] = NULL;
|
||||
reverse[3] = reverse[2];
|
||||
}
|
||||
|
||||
short n_u =uSegments;
|
||||
short n_v =vSegments;
|
||||
short cond_u = (uVisEdges>uSegments)?(uSegments-1):uVisEdges;
|
||||
short cond_v = (vVisEdges>vSegments)?(vSegments-1):vVisEdges;
|
||||
|
||||
int i,j;
|
||||
|
||||
reverse[2] = !reverse[2];
|
||||
reverse[3] = !reverse[3];
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
init_vdim(&vdim[i], sizeof(D_POINT));
|
||||
}
|
||||
|
||||
D_POINT p_1,p_2;
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
if (hobj[i] == NULL) continue;
|
||||
int jnum = ((i % 2) == 0) ? n_u : n_v;
|
||||
sgFloat dt = 1. / (jnum - 1);
|
||||
sgFloat t;
|
||||
if (reverse[i]) {
|
||||
t = 1.;
|
||||
dt = -dt;
|
||||
} else {
|
||||
t = 0.;
|
||||
}
|
||||
if (!init_get_point_on_path(hobj[i], NULL))
|
||||
{
|
||||
assert(0);
|
||||
global_sg_error = SG_ER_INTERNAL;
|
||||
for (i = 0; i < 4; i++)
|
||||
free_vdim(&vdim[i]);
|
||||
return NULL;
|
||||
}
|
||||
if (fourthSide == NULL && i==1) {
|
||||
// pstart
|
||||
if (reverse[i])
|
||||
t = 0.;
|
||||
else
|
||||
t = 1.;
|
||||
if (!get_point_on_path(t, &p_1))
|
||||
{
|
||||
assert(0);
|
||||
global_sg_error = SG_ER_INTERNAL;
|
||||
for (i = 0; i < 4; i++)
|
||||
free_vdim(&vdim[i]);
|
||||
return NULL;
|
||||
}
|
||||
if (reverse[i]) //RA
|
||||
t = 1.;
|
||||
else
|
||||
t = 0.;
|
||||
}
|
||||
for (j = 0; j < jnum; j++, t += dt) {
|
||||
/* RA ---- if (j == jnum - 1) {
|
||||
if (reverse[i])
|
||||
t = 0.;
|
||||
else
|
||||
t = 1.;
|
||||
}*/
|
||||
if (!get_point_on_path(t, &p_2))
|
||||
{
|
||||
assert(0);
|
||||
global_sg_error = SG_ER_INTERNAL;
|
||||
for (i = 0; i < 4; i++)
|
||||
free_vdim(&vdim[i]);
|
||||
return NULL;
|
||||
}
|
||||
if (!add_elem(&vdim[i], &p_2))
|
||||
{
|
||||
assert(0);
|
||||
global_sg_error = SG_ER_INTERNAL;
|
||||
for (i = 0; i < 4; i++)
|
||||
free_vdim(&vdim[i]);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
term_get_point_on_path();
|
||||
}
|
||||
if (fourthSide == NULL)
|
||||
{ //
|
||||
for (i = 0; i < n_v; i++) {
|
||||
if (!add_elem(&vdim[2], &p_1))
|
||||
{
|
||||
assert(0);
|
||||
global_sg_error = SG_ER_INTERNAL;
|
||||
for (i = 0; i < 4; i++)
|
||||
free_vdim(&vdim[i]);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!Coons_Surface(&vdim[0], &vdim[3], &vdim[2], &vdim[1],
|
||||
n_u, n_v, cond_u, cond_v, &hnew))
|
||||
{
|
||||
assert(0);
|
||||
global_sg_error = SG_ER_INTERNAL;
|
||||
for (i = 0; i < 4; i++)
|
||||
free_vdim(&vdim[i]);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
free_vdim(&vdim[i]);
|
||||
|
||||
global_sg_error = SG_ER_SUCCESS;
|
||||
return ObjectFromHandle(hnew);
|
||||
|
||||
}
|
||||
|
||||
sgCObject* sgSurfaces::Mesh(short dimens_1,
|
||||
short dimens_2,
|
||||
const SG_POINT* pnts)
|
||||
{
|
||||
if (dimens_1<2 || dimens_2<2)
|
||||
{
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_UNKNOWN;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pnts==NULL)
|
||||
{
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_NULL_POINTER;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LISTH listh_res;
|
||||
MESHDD mesh_data;
|
||||
MNODE tmp_node;
|
||||
|
||||
mesh_data.m = dimens_1;
|
||||
mesh_data.n = dimens_2;
|
||||
|
||||
init_vdim(&mesh_data.vdim,sizeof(MNODE));
|
||||
|
||||
for(int i = 0; i < mesh_data.m; i++)
|
||||
{
|
||||
for(int j = 0; j < mesh_data.n; j++)
|
||||
{
|
||||
memcpy(&tmp_node.p,&(pnts[i*mesh_data.n+j]),sizeof(D_POINT));
|
||||
tmp_node.num = COND_U | COND_V;
|
||||
if(!add_elem( &mesh_data.vdim, &tmp_node))
|
||||
{
|
||||
free_vdim(&mesh_data.vdim);
|
||||
global_sg_error = SG_ER_INTERNAL;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init_listh(&listh_res);
|
||||
|
||||
if(!np_create_brep(&mesh_data, &listh_res))
|
||||
{
|
||||
assert(0);
|
||||
global_sg_error = SG_ER_INTERNAL;
|
||||
free_vdim(&mesh_data.vdim);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hOBJ hnew = listh_res.hhead;
|
||||
|
||||
if(!hnew)
|
||||
{
|
||||
assert(0);
|
||||
global_sg_error = SG_ER_INTERNAL;
|
||||
free_vdim(&mesh_data.vdim);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
free_vdim(&mesh_data.vdim);
|
||||
|
||||
global_sg_error = SG_ER_SUCCESS;
|
||||
return ObjectFromHandle(hnew);
|
||||
}
|
||||
|
||||
sgCObject* sgSurfaces::SewSurfaces(const sgC3DObject** surfaces, int surf_count)
|
||||
{
|
||||
if (surfaces==NULL || surf_count<2)
|
||||
{
|
||||
global_sg_error = SG_ER_BAD_ARGUMENT_NULL_POINTER;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
hOBJ* select_list_before = NULL;
|
||||
int select_list_before_size = 0;
|
||||
if (selected.num>0)
|
||||
{
|
||||
select_list_before = (hOBJ*)SGMalloc((selected.num)*sizeof(hOBJ));
|
||||
select_list_before_size = selected.num;
|
||||
hOBJ tmp_hobj = selected.hhead;
|
||||
hOBJ tmp_hobj_next;
|
||||
int tmpI = 0;
|
||||
while(tmp_hobj)
|
||||
{
|
||||
select_list_before[tmpI] = tmp_hobj;
|
||||
get_next_item_z(SEL_LIST, tmp_hobj, &tmp_hobj_next);
|
||||
((lpOBJ)tmp_hobj)->extendedClass->Select(false);
|
||||
tmpI++;
|
||||
tmp_hobj = tmp_hobj_next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
short* object_statuses = (short*)SGMalloc((surf_count)*sizeof(short));
|
||||
for (int i=0;i<surf_count;i++)
|
||||
{
|
||||
if (surfaces[i]==NULL)
|
||||
{
|
||||
for (int j=0;j<i;j++)
|
||||
{
|
||||
((lpOBJ)GetObjectHandle(surfaces[j]))->status = object_statuses[j];
|
||||
}
|
||||
SGFree(object_statuses);
|
||||
|
||||
for (int i=0;i<select_list_before_size;i++)
|
||||
((lpOBJ)select_list_before[i])->extendedClass->Select(true);
|
||||
SGFree(select_list_before);
|
||||
|
||||
global_sg_error = SG_ER_INTERNAL;
|
||||
return NULL;
|
||||
}
|
||||
object_statuses[i] = ((lpOBJ)GetObjectHandle(surfaces[i]))->status;
|
||||
}
|
||||
|
||||
|
||||
LISTH listh_surf;
|
||||
init_listh(&listh_surf);
|
||||
|
||||
for (int i=0;i<surf_count;i++)
|
||||
attach_item_tail_z(SEL_LIST,&listh_surf, GetObjectHandle(surfaces[i]));
|
||||
|
||||
hOBJ hnew = NULL;
|
||||
|
||||
if(!sew(&listh_surf,&hnew, eps_d))
|
||||
{
|
||||
for (int i=0;i<surf_count;i++)
|
||||
{
|
||||
((lpOBJ)GetObjectHandle(surfaces[i]))->status = object_statuses[i];
|
||||
}
|
||||
SGFree(object_statuses);
|
||||
|
||||
for (int i=0;i<select_list_before_size;i++)
|
||||
((lpOBJ)select_list_before[i])->extendedClass->Select(true);
|
||||
SGFree(select_list_before);
|
||||
|
||||
global_sg_error = SG_ER_INTERNAL;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (int i=0;i<surf_count;i++)
|
||||
detach_item_z(SEL_LIST,&listh_surf, GetObjectHandle(surfaces[i]));
|
||||
|
||||
for (int i=0;i<surf_count;i++)
|
||||
{
|
||||
((lpOBJ)GetObjectHandle(surfaces[i]))->status = object_statuses[i];
|
||||
}
|
||||
SGFree(object_statuses);
|
||||
|
||||
for (int i=0;i<select_list_before_size;i++)
|
||||
((lpOBJ)select_list_before[i])->extendedClass->Select(true);
|
||||
SGFree(select_list_before);
|
||||
|
||||
global_sg_error = SG_ER_SUCCESS;
|
||||
return ObjectFromHandle(hnew);
|
||||
|
||||
}
|
||||
|
||||
|
||||
sgCObject* sgSurfaces::LinearSurfaceFromSections(const sgC2DObject& firstSide,
|
||||
const sgC2DObject& secondSide,
|
||||
sgFloat firstParam,
|
||||
bool isClose)
|
||||
{
|
||||
short degree=0;
|
||||
short q=0;
|
||||
|
||||
{
|
||||
lpOBJ obj = (lpOBJ)GetObjectHandle(&firstSide);
|
||||
if( obj->type==OLINE || obj->type==OARC || obj->type==OCIRCLE || obj->type==OPATH )
|
||||
q=2;
|
||||
else
|
||||
q = ((lpGEO_SPLINE)obj->geo_data)->degree; //case OSPLINE:
|
||||
if( q > degree )
|
||||
degree=q;
|
||||
|
||||
obj = (lpOBJ)GetObjectHandle(&secondSide);
|
||||
if( obj->type==OLINE || obj->type==OARC || obj->type==OCIRCLE || obj->type==OPATH )
|
||||
q=2;
|
||||
else
|
||||
q = ((lpGEO_SPLINE)obj->geo_data)->degree; //case OSPLINE:
|
||||
if( q > degree )
|
||||
degree=q;
|
||||
}
|
||||
|
||||
short p=degree;
|
||||
|
||||
LISTH listh_ribs;
|
||||
init_listh(&listh_ribs);
|
||||
|
||||
hOBJ* select_list_before = NULL;
|
||||
int select_list_before_size = 0;
|
||||
if (selected.num>0)
|
||||
{
|
||||
select_list_before = (hOBJ*)SGMalloc((selected.num)*sizeof(hOBJ));
|
||||
select_list_before_size = selected.num;
|
||||
hOBJ tmp_hobj = selected.hhead;
|
||||
hOBJ tmp_hobj_next;
|
||||
int tmpI = 0;
|
||||
while(tmp_hobj)
|
||||
{
|
||||
select_list_before[tmpI] = tmp_hobj;
|
||||
get_next_item_z(SEL_LIST, tmp_hobj, &tmp_hobj_next);
|
||||
((lpOBJ)tmp_hobj)->extendedClass->Select(false);
|
||||
tmpI++;
|
||||
tmp_hobj = tmp_hobj_next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
short object_statuses[2];
|
||||
object_statuses[0] = ((lpOBJ)GetObjectHandle(&firstSide))->status;
|
||||
object_statuses[1] = ((lpOBJ)GetObjectHandle(&secondSide))->status;
|
||||
|
||||
|
||||
attach_item_tail_z(SEL_LIST, &listh_ribs, GetObjectHandle(&firstSide));
|
||||
attach_item_tail_z(SEL_LIST, &listh_ribs, GetObjectHandle(&secondSide));
|
||||
|
||||
D_POINT spin_pnts[2];
|
||||
SG_POINT tmpPnt[2];
|
||||
tmpPnt[0] = firstSide.GetPointFromCoefficient(firstParam);
|
||||
tmpPnt[1] = secondSide.GetPointFromCoefficient(0.0);
|
||||
memcpy(&spin_pnts[0],&(tmpPnt[0]),sizeof(D_POINT));
|
||||
memcpy(&spin_pnts[1],&(tmpPnt[1]),sizeof(D_POINT));
|
||||
|
||||
hOBJ hnew;
|
||||
bool isSidesClosed = (firstSide.IsClosed() && secondSide.IsClosed());
|
||||
bool canSolid = (isClose && isSidesClosed && firstSide.IsPlane(NULL,NULL) && secondSide.IsPlane(NULL,NULL));
|
||||
//----------------Ruled_surface----------------->>>>>>>>>>>>>
|
||||
if (!Ruled_Surface(&listh_ribs, spin_pnts, degree, p,
|
||||
isSidesClosed, canSolid, &hnew))
|
||||
{
|
||||
((lpOBJ)GetObjectHandle(&firstSide))->status = object_statuses[0];
|
||||
((lpOBJ)GetObjectHandle(&secondSide))->status = object_statuses[1];
|
||||
|
||||
for (int i=0;i<select_list_before_size;i++)
|
||||
((lpOBJ)select_list_before[i])->extendedClass->Select(true);
|
||||
SGFree(select_list_before);
|
||||
|
||||
global_sg_error = SG_ER_INTERNAL;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
detach_item_z(SEL_LIST,&listh_ribs, GetObjectHandle(&firstSide));
|
||||
detach_item_z(SEL_LIST,&listh_ribs, GetObjectHandle(&secondSide));
|
||||
|
||||
((lpOBJ)GetObjectHandle(&firstSide))->status = object_statuses[0];
|
||||
((lpOBJ)GetObjectHandle(&secondSide))->status = object_statuses[1];
|
||||
|
||||
for (int i=0;i<select_list_before_size;i++)
|
||||
((lpOBJ)select_list_before[i])->extendedClass->Select(true);
|
||||
SGFree(select_list_before);
|
||||
|
||||
global_sg_error = SG_ER_SUCCESS;
|
||||
return ObjectFromHandle(hnew);
|
||||
}
|
||||
|
||||
|
||||
|
||||
sgCObject* sgSurfaces::SplineSurfaceFromSections(const sgC2DObject** sections,
|
||||
const sgFloat* params,
|
||||
int sections_count,
|
||||
bool isClose)
|
||||
{
|
||||
|
||||
if (sections==NULL || sections_count<3 || params==NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
short degree=0;
|
||||
short q=0;
|
||||
|
||||
for (int i=0;i<sections_count;i++)
|
||||
{
|
||||
lpOBJ obj = (lpOBJ)GetObjectHandle(sections[i]);
|
||||
if( obj->type==OLINE || obj->type==OARC || obj->type==OCIRCLE || obj->type==OPATH )
|
||||
q=2;
|
||||
else
|
||||
q = ((lpGEO_SPLINE)obj->geo_data)->degree; //case OSPLINE:
|
||||
if( q > degree )
|
||||
degree=q;
|
||||
}
|
||||
|
||||
short p=degree;
|
||||
|
||||
LISTH listh_ribs;
|
||||
init_listh(&listh_ribs);
|
||||
|
||||
hOBJ* select_list_before = NULL;
|
||||
int select_list_before_size = 0;
|
||||
if (selected.num>0)
|
||||
{
|
||||
select_list_before = (hOBJ*)SGMalloc((selected.num)*sizeof(hOBJ));
|
||||
select_list_before_size = selected.num;
|
||||
hOBJ tmp_hobj = selected.hhead;
|
||||
hOBJ tmp_hobj_next;
|
||||
int tmpI = 0;
|
||||
while(tmp_hobj)
|
||||
{
|
||||
select_list_before[tmpI] = tmp_hobj;
|
||||
get_next_item_z(SEL_LIST, tmp_hobj, &tmp_hobj_next);
|
||||
((lpOBJ)tmp_hobj)->extendedClass->Select(false);
|
||||
tmpI++;
|
||||
tmp_hobj = tmp_hobj_next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
short* object_statuses = (short*)SGMalloc((sections_count)*sizeof(short));
|
||||
for (int i=0;i<sections_count;i++)
|
||||
{
|
||||
if (sections[i]==NULL)
|
||||
{
|
||||
for (int j=0;j<i;j++)
|
||||
{
|
||||
((lpOBJ)GetObjectHandle(sections[j]))->status = object_statuses[j];
|
||||
}
|
||||
SGFree(object_statuses);
|
||||
|
||||
for (int i=0;i<select_list_before_size;i++)
|
||||
((lpOBJ)select_list_before[i])->extendedClass->Select(true);
|
||||
SGFree(select_list_before);
|
||||
|
||||
global_sg_error = SG_ER_INTERNAL;
|
||||
return NULL;
|
||||
}
|
||||
object_statuses[i] = ((lpOBJ)GetObjectHandle(sections[i]))->status;
|
||||
}
|
||||
|
||||
|
||||
for (int i=0;i<sections_count;i++)
|
||||
{
|
||||
attach_item_tail_z(SEL_LIST, &listh_ribs, GetObjectHandle(sections[i]));
|
||||
}
|
||||
|
||||
D_POINT* spin_pnts = (D_POINT*)SGMalloc(sections_count*sizeof(D_POINT));
|
||||
|
||||
for (int i=0;i<sections_count;i++)
|
||||
{
|
||||
SG_POINT aaaPnt = sections[i]->GetPointFromCoefficient(params[i]);
|
||||
memcpy(&spin_pnts[i],&(aaaPnt),
|
||||
sizeof(D_POINT));
|
||||
}
|
||||
|
||||
|
||||
hOBJ hnew;
|
||||
//----------------Ruled_surface----------------->>>>>>>>>>>>>
|
||||
if (!Skin_Surface(&listh_ribs, spin_pnts,(short)listh_ribs.num, p, q,
|
||||
isClose,!isClose,isClose,&hnew))
|
||||
{
|
||||
SGFree(spin_pnts);
|
||||
|
||||
for (int i=0;i<sections_count;i++)
|
||||
{
|
||||
((lpOBJ)GetObjectHandle(sections[i]))->status = object_statuses[i];
|
||||
}
|
||||
SGFree(object_statuses);
|
||||
|
||||
for (int i=0;i<select_list_before_size;i++)
|
||||
((lpOBJ)select_list_before[i])->extendedClass->Select(true);
|
||||
SGFree(select_list_before);
|
||||
|
||||
global_sg_error = SG_ER_INTERNAL;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SGFree(spin_pnts);
|
||||
|
||||
for (int i=0;i<sections_count;i++)
|
||||
detach_item_z(SEL_LIST,&listh_ribs, GetObjectHandle(sections[i]));
|
||||
|
||||
for (int i=0;i<sections_count;i++)
|
||||
{
|
||||
((lpOBJ)GetObjectHandle(sections[i]))->status = object_statuses[i];
|
||||
}
|
||||
SGFree(object_statuses);
|
||||
|
||||
for (int i=0;i<select_list_before_size;i++)
|
||||
((lpOBJ)select_list_before[i])->extendedClass->Select(true);
|
||||
SGFree(select_list_before);
|
||||
|
||||
global_sg_error = SG_ER_SUCCESS;
|
||||
return ObjectFromHandle(hnew);
|
||||
}
|
||||
@@ -0,0 +1,406 @@
|
||||
#include "..//Core//sg.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
sgCFont* temp_font = NULL;
|
||||
|
||||
bool sgFontManager::AttachFont(sgCFont* fnt)
|
||||
{
|
||||
if (!fnt || !fnt->m_handle || fnt->m_length==0)
|
||||
return false;
|
||||
|
||||
lpFONT font = NULL;
|
||||
IDENT_V id;
|
||||
ULONG len;
|
||||
//
|
||||
id = ft_bd->ft_listh[FTFONT].head;
|
||||
while(id){
|
||||
if(0 ==(font = (FONT *)alloc_and_get_ft_value(id, &len)))
|
||||
{
|
||||
assert(0);
|
||||
sgCFont::UnloadFont(fnt);
|
||||
return false;
|
||||
}
|
||||
if(!strcmp(fnt->GetFontData()->name, font->name))
|
||||
{
|
||||
SGFree(font);
|
||||
sgCFont::UnloadFont(fnt);
|
||||
return false;
|
||||
}
|
||||
SGFree(font);
|
||||
font = NULL;
|
||||
if(!il_get_next_item(&ft_bd->vd, id, &id))
|
||||
{
|
||||
assert(0);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
id = add_ft_value(FTFONT, fnt->m_handle, fnt->m_length);
|
||||
|
||||
if(!id)
|
||||
return false;
|
||||
|
||||
fnt->m_id = id;
|
||||
SGFree(fnt->m_handle);
|
||||
fnt->m_handle = NULL;
|
||||
fnt->m_length = 0;
|
||||
|
||||
if (ft_bd->curr_font==0)
|
||||
ft_bd->def_font = ft_bd->curr_font = id;
|
||||
|
||||
delete fnt;
|
||||
fnt = NULL;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned int sgFontManager::GetFontsCount()
|
||||
{
|
||||
return ft_bd->ft_listh[FTFONT].num;
|
||||
}
|
||||
|
||||
const sgCFont* sgFontManager::GetFont(unsigned int numb)
|
||||
{
|
||||
lpFONT fnt = NULL;
|
||||
IDENT_V id;
|
||||
|
||||
if ((long)numb>=ft_bd->ft_listh[FTFONT].num)
|
||||
return NULL;
|
||||
//
|
||||
id = ft_bd->ft_listh[FTFONT].head;
|
||||
|
||||
for (unsigned int i=0;i<numb;i++)
|
||||
if(!il_get_next_item(&ft_bd->vd, id, &id))
|
||||
return NULL;
|
||||
if (temp_font)
|
||||
{
|
||||
delete temp_font;
|
||||
temp_font = NULL;
|
||||
}
|
||||
|
||||
temp_font = new sgCFont(NULL,0,id);
|
||||
return temp_font;
|
||||
}
|
||||
|
||||
bool sgFontManager::SetCurrentFont(unsigned int numb)
|
||||
{
|
||||
IDENT_V id;
|
||||
|
||||
if ((long)numb>=ft_bd->ft_listh[FTFONT].num)
|
||||
return false;
|
||||
//
|
||||
id = ft_bd->ft_listh[FTFONT].head;
|
||||
for (unsigned int i=0;i<numb;i++)
|
||||
if(!il_get_next_item(&ft_bd->vd, id, &id))
|
||||
return NULL;
|
||||
ft_bd->curr_font = id;
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned int sgFontManager::GetCurrentFont()
|
||||
{
|
||||
IDENT_V id;
|
||||
//
|
||||
id = ft_bd->ft_listh[FTFONT].head;
|
||||
unsigned int res = 0;
|
||||
while(id)
|
||||
{
|
||||
if (id==ft_bd->curr_font)
|
||||
return res;
|
||||
if(!il_get_next_item(&ft_bd->vd, id, &id))
|
||||
{
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
res++;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static std::vector<SG_LINE> lines_buffer;
|
||||
|
||||
static BOOL lines_collector_func(lpD_POINT p1, lpD_POINT p2, void* us_d)
|
||||
{
|
||||
SG_LINE tmpL;
|
||||
assert(p1);
|
||||
assert(p2);
|
||||
memcpy(&tmpL.p1,p1,sizeof(D_POINT));
|
||||
memcpy(&tmpL.p2,p2,sizeof(D_POINT));
|
||||
|
||||
lines_buffer.push_back(tmpL);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void FillLinesArrayfromGeoText(lpGEO_TEXT geoT)
|
||||
{
|
||||
lines_buffer.clear();
|
||||
assert(geoT);
|
||||
draw_geo_text(geoT,lines_collector_func,NULL);
|
||||
}
|
||||
|
||||
|
||||
sgCText::sgCText():sgCObject()
|
||||
{
|
||||
m_lines = NULL;
|
||||
m_lines_count=0;
|
||||
m_text = NULL;
|
||||
}
|
||||
|
||||
sgCText::~sgCText()
|
||||
{
|
||||
if (m_text)
|
||||
{
|
||||
SGFree(m_text);
|
||||
m_text = NULL;
|
||||
}
|
||||
if (m_lines)
|
||||
{
|
||||
delete [] m_lines;
|
||||
m_lines = NULL;
|
||||
m_lines_count=0;
|
||||
}
|
||||
}
|
||||
|
||||
sgCText::sgCText(SG_OBJ_HANDLE objH):sgCObject(objH)
|
||||
{
|
||||
m_lines = NULL;
|
||||
m_lines_count=0;
|
||||
m_text = NULL;
|
||||
|
||||
char* typeID = "{0000000000000-0000-0000-000000000006}";
|
||||
set_hobj_attr_value(id_TypeID, objH, typeID);
|
||||
|
||||
lpOBJ pobj = (lpOBJ)objH;
|
||||
|
||||
FillLinesArrayfromGeoText(reinterpret_cast<lpGEO_TEXT>(pobj->geo_data));
|
||||
|
||||
size_t lbs = lines_buffer.size();
|
||||
if (lbs>0)
|
||||
{
|
||||
m_lines_count = lbs;
|
||||
m_lines = new SG_LINE[lbs];
|
||||
memcpy(m_lines, &lines_buffer[0], sizeof(SG_LINE)*m_lines_count);
|
||||
}
|
||||
lines_buffer.clear();
|
||||
|
||||
PostCreate();
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool sgCText::ApplyTempMatrix()
|
||||
{
|
||||
if (!sgCObject::ApplyTempMatrix())
|
||||
return false;
|
||||
if (m_lines)
|
||||
{
|
||||
delete [] m_lines;
|
||||
m_lines = NULL;
|
||||
m_lines_count=0;
|
||||
}
|
||||
lpOBJ pobj = (lpOBJ)GetObjectHandle(this);
|
||||
|
||||
FillLinesArrayfromGeoText(reinterpret_cast<lpGEO_TEXT>(pobj->geo_data));
|
||||
|
||||
size_t lbs = lines_buffer.size();
|
||||
if (lbs>0)
|
||||
{
|
||||
m_lines_count = lbs;
|
||||
m_lines = new SG_LINE[lbs];
|
||||
memcpy(m_lines, &lines_buffer[0], sizeof(SG_LINE)*m_lines_count);
|
||||
}
|
||||
lines_buffer.clear();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
sgCText* sgCText::Create(const sgCFont* fnt, const SG_TEXT_STYLE& text_stl,const char* textStr)
|
||||
{
|
||||
|
||||
if (fnt==NULL || textStr==NULL )
|
||||
return NULL;
|
||||
|
||||
GEO_TEXT gtext;
|
||||
|
||||
// was - RA
|
||||
//memcpy(>ext.style,&text_stl,sizeof(SG_TEXT_STYLE));//ft_bd->curr_style;
|
||||
|
||||
// new - RA
|
||||
gtext.style.status = text_stl.state;
|
||||
gtext.style.height = text_stl.height;
|
||||
gtext.style.scale = text_stl.proportions;
|
||||
gtext.style.angle = text_stl.angle;
|
||||
gtext.style.dhor = text_stl.horiz_space_proportion;
|
||||
gtext.style.dver = text_stl.vert_space_proportion;
|
||||
|
||||
gtext.font_id = fnt->m_id;//ft_bd->curr_font;
|
||||
|
||||
IDENT_V id;
|
||||
ULONG len;
|
||||
UCHAR *exist_txt=NULL;
|
||||
bool exist_this_text = false;
|
||||
|
||||
id = ft_bd->ft_listh[FTTEXT].head;
|
||||
|
||||
while(id){
|
||||
if(0 ==(exist_txt = (UCHAR *)alloc_and_get_ft_value(id, &len)))
|
||||
return NULL;
|
||||
if(!strcmp((char*)exist_txt, textStr))
|
||||
{
|
||||
SGFree(exist_txt);
|
||||
gtext.text_id = id;
|
||||
exist_this_text = true;
|
||||
break;
|
||||
}
|
||||
SGFree(exist_txt); exist_txt = NULL;
|
||||
if(!il_get_next_item(&ft_bd->vd, id, &id))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!exist_this_text)
|
||||
gtext.text_id = add_ft_value(FTTEXT, const_cast<char*>(textStr), strlen(textStr)+1);
|
||||
if(!gtext.text_id)
|
||||
return NULL;
|
||||
|
||||
if(get_text_geo_par(>ext) != G_OK)
|
||||
{
|
||||
if (!exist_this_text)
|
||||
delete_ft_item(FTTEXT, gtext.text_id);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hOBJ obj = create_simple_obj_loc(OTEXT, >ext);
|
||||
|
||||
if (!obj)
|
||||
{
|
||||
assert(0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sgCText* newT=new sgCText(obj);
|
||||
|
||||
char* typeID = "{0000000000000-0000-0000-000000000006}";
|
||||
set_hobj_attr_value(id_TypeID, obj, typeID);
|
||||
|
||||
|
||||
newT->PostCreate();
|
||||
|
||||
return newT;
|
||||
}
|
||||
|
||||
|
||||
const SG_LINE* sgCText::GetLines() const
|
||||
{
|
||||
return m_lines;
|
||||
}
|
||||
|
||||
int sgCText::GetLinesCount() const
|
||||
{
|
||||
return m_lines_count;
|
||||
}
|
||||
|
||||
SG_TEXT_STYLE sgCText::GetStyle() const
|
||||
{
|
||||
lpOBJ obj = (lpOBJ)GetObjectHandle(this);
|
||||
|
||||
SG_TEXT_STYLE retStl;
|
||||
memcpy(&retStl, &((lpGEO_TEXT)(obj->geo_data))->style, sizeof(SG_TEXT_STYLE));
|
||||
|
||||
return retStl;
|
||||
}
|
||||
|
||||
const char* sgCText::GetText()
|
||||
{
|
||||
lpOBJ obj = (lpOBJ)GetObjectHandle(this);
|
||||
|
||||
if (m_text!=NULL)
|
||||
return m_text;
|
||||
|
||||
IDENT_V id = ((lpGEO_TEXT)(obj->geo_data))->text_id;
|
||||
ULONG len;
|
||||
|
||||
if(0 ==(m_text = (char*)alloc_and_get_ft_value(id, &len)))
|
||||
{
|
||||
assert(0);
|
||||
return NULL;
|
||||
}
|
||||
return m_text;
|
||||
}
|
||||
|
||||
unsigned int sgCText::GetFont()
|
||||
{
|
||||
lpOBJ obj = (lpOBJ)GetObjectHandle(this);
|
||||
|
||||
IDENT_V id;
|
||||
//
|
||||
id = ft_bd->ft_listh[FTFONT].head;
|
||||
unsigned int res = 0;
|
||||
while(id)
|
||||
{
|
||||
if (id==((lpGEO_TEXT)(obj->geo_data))->font_id)
|
||||
return res;
|
||||
if(!il_get_next_item(&ft_bd->vd, id, &id))
|
||||
{
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
res++;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
bool sgCText::GetWorldMatrix(sgCMatrix& mtrx) const
|
||||
{
|
||||
GEO_TEXT oldGeo;
|
||||
get_simple_obj_geo(GetObjectHandle(this), &oldGeo);
|
||||
sgCMatrix* newM = new sgCMatrix(oldGeo.matr);
|
||||
mtrx.SetMatrix(newM);
|
||||
delete newM;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static SG_DRAW_LINE_FUNC drLF = NULL;
|
||||
|
||||
static sgCMatrix* drMatr = NULL;
|
||||
|
||||
static BOOL lineFnkForCore(lpD_POINT pb, lpD_POINT pe, void *usrD)
|
||||
{
|
||||
assert(drLF);
|
||||
SG_POINT* pBeg = (SG_POINT*)(pb);
|
||||
SG_POINT* pEnd = (SG_POINT*)(pe);
|
||||
if (drMatr)
|
||||
{
|
||||
drMatr->ApplyMatrixToPoint(*pBeg);
|
||||
drMatr->ApplyMatrixToPoint(*pEnd);
|
||||
}
|
||||
drLF(pBeg,pEnd);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool sgCText::Draw(const sgCFont* fnt,
|
||||
const SG_TEXT_STYLE& stle,
|
||||
sgCMatrix* mtrx,
|
||||
const char* strng,
|
||||
SG_DRAW_LINE_FUNC dlf)
|
||||
{
|
||||
if (fnt==NULL || strng==NULL || dlf==NULL)
|
||||
return false;
|
||||
|
||||
drLF = dlf;
|
||||
drMatr = mtrx;
|
||||
lpFONT fntHndl = (lpFONT)const_cast<SG_FONT_DATA*>(fnt->GetFontData());
|
||||
TSTYLE tmpTSt;
|
||||
memcpy(&tmpTSt, &stle, sizeof(SG_TEXT_STYLE));
|
||||
draw_text(fntHndl, &tmpTSt,
|
||||
const_cast<UCHAR*>(reinterpret_cast<const UCHAR*>(strng)),
|
||||
lineFnkForCore, NULL);
|
||||
drLF = NULL;
|
||||
drMatr = NULL;
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
#include "..//Core//sg.h"
|
||||
|
||||
sgCTorus::sgCTorus():sgC3DObject()
|
||||
{
|
||||
}
|
||||
|
||||
sgCTorus::~sgCTorus()
|
||||
{
|
||||
}
|
||||
|
||||
sgCTorus::sgCTorus(SG_OBJ_HANDLE objH):sgC3DObject(objH)
|
||||
{
|
||||
char* typeID = "{0000000000000-0000-0005-000000000009}";
|
||||
set_hobj_attr_value(id_TypeID, objH, typeID);
|
||||
|
||||
PostCreate();
|
||||
|
||||
}
|
||||
|
||||
sgCTorus* sgCTorus::Create(sgFloat r1,sgFloat r2,short m1,short m2)
|
||||
{
|
||||
if (r1<eps_d ||
|
||||
r2<eps_d ||
|
||||
r2>r1 ||
|
||||
m1<2 ||
|
||||
m2<2)
|
||||
return NULL;
|
||||
|
||||
sgFloat par[4];
|
||||
par[0] = r1;
|
||||
par[1] = r2;
|
||||
par[2] = (sgFloat)m1;
|
||||
par[3] = (sgFloat)m2;
|
||||
|
||||
hOBJ hO = create_primitive_obj(TOR, par);
|
||||
assert(hO);
|
||||
|
||||
sgCTorus* newT=new sgCTorus(hO);
|
||||
|
||||
newT->PostCreate();
|
||||
|
||||
return newT;
|
||||
}
|
||||
|
||||
|
||||
void sgCTorus::GetGeometry(SG_TORUS& res) const
|
||||
{
|
||||
lpOBJ obj = static_cast<lpOBJ>(GetObjectHandle(this));
|
||||
assert(obj);
|
||||
|
||||
lpGEO_BREP geo = (lpGEO_BREP)(obj->geo_data);
|
||||
assert(geo);
|
||||
|
||||
LNP lnp;
|
||||
|
||||
if ( !read_elem(&vd_brep,geo->num,&lnp) )
|
||||
{
|
||||
assert(0);
|
||||
}
|
||||
|
||||
lpCSG csg = static_cast<lpCSG>(lnp.hcsg);
|
||||
assert(csg);
|
||||
|
||||
sgFloat* pars = (sgFloat*)malloc(csg->size);
|
||||
|
||||
memcpy(pars, csg->data, csg->size);
|
||||
|
||||
res.Radius1 = pars[0];
|
||||
res.Radius2 = pars[1];
|
||||
res.MeridiansCount1 = static_cast<short>(pars[2]);
|
||||
res.MeridiansCount2 = static_cast<short>(pars[3]);
|
||||
|
||||
free(pars);
|
||||
}
|
||||
Reference in New Issue
Block a user