您现在的位置:网站首页 > 经验分享 > 鞋业CAD软件柔性内核技术:源码[9-1
设计师介绍:

昵称:烦夫子
类别:界面/平面设计师
年龄:37
现所在地:北京

查看该设计师的主页>>

关注好友

统计中心

主页浏览总数:24096
总积分:89
文章数:88
作品数:70

鞋业CAD软件柔性内核技术:源码[9-1

作者:烦夫子  更新时间: 2007-11-19   浏览人数:17192  评论:0  
分享到:
开源软件:
                         柔性图形内核之九
                         Shape
//应用于CAD/CAM图形类程序设计
//我将逐步开放数以十万记的自主版权软件源码,谢谢大家的支持!
//以后将开源的项目: CAD、工控、机械设计图、电子布线图等

// Shape.cpp: implementation of the Shape class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "SoftDraw.h"
#include "Shape.h"
#include "global.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

/*----- Constructors ------------------------------------*/
//None
Shape::Shape (const Object * p) : Object (p)
{
 name = TShape;
 shape = SPoint;
 a = 1; b = 1;
 edangle = 0;
 stangle = PI2;
 p1 = Vector(0,0);
 p2 = Vector(0,0);
 p3 = Vector(0,0);
 p4 = Vector(0,0);
 radius = 1;
 color = RGB(0,0,255);

 previewmode = 0;
 //0:忽略, 1:慢笔, 2:慢刀, 3:快笔, 4:快刀, 5:半刀
 plottype = 2;
 GetMinMax ();
}

//Point
Shape::Shape (const Object * p, Vector& v1) : Object (p)
{
 name = TShape;
 a = 1; b = 1;
 edangle = 0;
 stangle = PI2;
 p2 = Vector(0,0);
 p3 = Vector(0,0);
 p4 = Vector(0,0);
 radius = 1;

 previewmode = 0;
 shape = SPoint;
 p1 = v1;
 color = RGB(0,0,255);

 //0:忽略, 1:慢笔, 2:慢刀, 3:快笔, 4:快刀, 5:半刀
 plottype = 2;

 GetMinMax ();
}

Shape::Shape (const Object * p, Vector& v1, Vector& v2) : Object (p)
{
 name = TShape;
 a = 1; b = 1;
 edangle = 0;
 stangle = PI2;
 p3 = Vector(0,0);
 p4 = Vector(0,0);
 radius = 1;

 previewmode = 0;
 shape = SLine;
 p1 = v1;
 p2 = v2;
 color = RGB(0,0,255);

 //0:忽略, 1:慢笔, 2:慢刀, 3:快笔, 4:快刀, 5:半刀
 plottype = 2;
 GetMinMax ();
}

Shape::Shape (const Object * p, Vector& v1, Vector& v2, Vector& v3, Vector& v4) : Object (p)
{
 name = TShape;
 a = 1; b = 1;
 edangle = 0;
 stangle = PI2;
 radius = 1;

 previewmode = 0;
 shape = SRectangle;
 p1 = v1;
 p2 = v2;
 p3 = v3;
 p4 = v4;
 color = RGB(0,0,255);
 //0:忽略, 1:慢笔, 2:慢刀, 3:快笔, 4:快刀, 5:半刀
 plottype = 2;
 GetMinMax ();
}

Shape::Shape (const Object * p, Vector& v1, float rr) : Object (p)
{
 name = TShape;
 a = 1; b = 1;
 p2 = Vector(0,0);
 p3 = Vector(0,0);
 p4 = Vector(0,0);

 shape = SCircle;
 p1 = v1;
 radius = rr;
 stangle = 0;
 edangle = PI2;
 color = RGB(0,0,255);
 previewmode = 0;

 //0:忽略, 1:慢笔, 2:慢刀, 3:快笔, 4:快刀, 5:半刀
 plottype = 2;
 GetMinMax ();

}

Shape::Shape (const Object * p, Vector& v1,BOOL bChange) : Object (p)
{
 name = TShape;
 a = 1; b = 1;
 p2 = Vector(0,0);
 p3 = Vector(0,0);
 p4 = Vector(0,0);

 shape = SHole;
 p1 = v1;
 radius = 1;
 stangle = 0;
 edangle = PI2;
 color = RGB(0,0,0);
 previewmode = 0;
 //0:忽略, 1:慢笔, 2:慢刀, 3:快笔, 4:快刀, 5:半刀
 plottype = 2;
 GetMinMax ();

}

Shape::Shape (const Object * p, Vector& v1, float rr, float sta, float eda) : Object (p)
{
 name = TShape;
 a = 1; b = 1;
 p2 = Vector(0,0);
 p3 = Vector(0,0);
 p4 = Vector(0,0);
 previewmode = 0;

 shape = SArc;
 p1 = v1;  //center
 radius = rr; //radius
 stangle = sta; //start angle
 edangle = eda; //end angle
 color = RGB(0,0,255);
 //0:忽略, 1:慢笔, 2:慢刀, 3:快笔, 4:快刀, 5:半刀
 plottype = 2;
 GetMinMax ();
}

// 功能:在装饰库中画椭圆
Shape::Shape (const Object * p, Vector& v1, float aa, float bb) : Object (p)
{
 name = TShape;
 p2 = Vector(0,0);
 p3 = Vector(0,0);
 p4 = Vector(0,0);
 radius = 1;

 shape = SEllipse;
 p1 = v1;  //center
 a = aa;   //long axis
 b = bb;   //short axis
 stangle = 0; //obliquing angle
 edangle = 0;
 color = RGB(0,0,255);
 previewmode = 0;

 //0:忽略, 1:慢笔, 2:慢刀, 3:快笔, 4:快刀, 5:半刀
 plottype = 2;
 GetMinMax ();
}

/*----- Operators ---------------------------------------*/
BOOL Shape::IsInRegion(CRgn *region) const
{
 switch (shape) {
  case SPoint:
   return region->PtInRegion(p1.x, p1.y);
  case SLine:
   return region->PtInRegion(p1.x, p1.y) && region->PtInRegion(p2.x, p2.y);
  case SCircle:
  {
   return region->PtInRegion(p1.x, p1.y) &&
    region->PtInRegion(p1.x-radius, p1.y) &&
    region->PtInRegion(p1.x+radius, p1.y) &&
    region->PtInRegion(p1.x, p1.y-radius) &&
    region->PtInRegion(p1.x, p1.y+radius) &&
    region->PtInRegion(p1.x-0.707*radius, p1.y-0.707*radius) &&
    region->PtInRegion(p1.x-0.707*radius, p1.y+0.707*radius) &&
    region->PtInRegion(p1.x+0.707*radius, p1.y-0.707*radius) &&
    region->PtInRegion(p1.x+0.707*radius, p1.y+0.707*radius) ;
  }
 }
 return 0;
}


void Shape::Draw (CDC* dc, float scale, DrawMode mode, int dispmode) const
//参数: dc, scale -- 显示比例, mode -- 显示模式
//返回: 无
{                   
 //显示图形
 Object::Draw (dc, scale, mode, dispmode);
}

void Shape::DrawOrder(CDC* dc, float scale, DrawMode mode) const
{
 CString csInd;
 int iInd;
 iInd = parent->GetIndex(this);
 csInd.Format("%d", iInd);

 Vector v;
 VectorRun dp;
 switch(shape) {
  case SPoint:
   v = p1 * scale;
   break;
  case SLine:
   v = (p1 + p2) * scale * 0.5;
   break;
  case SRectangle:
   v = (p1 + p2 + p3 + p4) * 0.25;
   break;
  case SEllipse:
  case SCircle:
  case SArc:
   v = p1 * scale;
   break;
  default:
   break;
 }
 CFont font, *ofont;
 font.CreatePointFont(80, _T("Arial"));
 ofont = dc->SelectObject(&font);
 v = dp.WorldToDc(v);
 dc->TextOut(v.x, v.y, csInd);
 dc->SelectObject(ofont);
}

(目前有0人发表看法,  我要发表评论
我要评论:
  只有登录后才能评论!
评论者: 匿名游客    (立即登录 或 注册)