home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DOS/V Power Report 1997 March
/
VPR9703A.ISO
/
VPR_DATA
/
DOGA
/
SOURCES
/
PASM.LZH
/
DISPLAY.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1996-07-12
|
44KB
|
1,471 lines
/* Project partsasm
Project Team DoGA
Copyright (c) 1995. All Rights Reserved.
サブシステム: partsasm.apx Application
ファイル: display.cpp
作成者: Taka2
概要
====
TWinDisplay (TWindow) のインプリメンテーション用のソースファイル
*/
#include <owl\owlpch.h>
#pragma hdrstop
#include "design.h"
//#include "winframe.h"
#include "display.h"
#include "parts.h"
#include "status.h"
#include "syscolor.h"
#include "log.h"
#include <stdio.h>
//
// このアプリケーションで処理するすべてのメッセージ/コマンドの
// 応答テーブルを作成する
//
DEFINE_RESPONSE_TABLE1(TWinDisplay, TWindow)
//{{TWinDisplayRSP_TBL_BEGIN}}
EV_WM_LBUTTONDOWN,
EV_WM_MOUSEMOVE,
EV_WM_RBUTTONDOWN,
EV_WM_LBUTTONUP,
//{{TWinDisplayRSP_TBL_END}}
END_RESPONSE_TABLE;
//{{TWinDisplay Implementation}}
#if 0
static const TColor& cMarkerMove = TColor::LtRed;
static const TColor& cMarkerScale = TColor::LtMagenta;
static const TColor& cMarkerRot = TColor::LtBlue;
static const TColor& cGrid = TColor::LtYellow;
static const TColor& cGridZero = TColor::LtCyan;
#endif
static const int minimumcube = 1, minimummarker = 4;
TWinDisplay::TWinDisplay(TWindow* parent, DesignData *d, SelectType sel, int x, int y, int w, int h):
TWindow(parent, 0, 0)
{
SetBkgndColor(TColor::LtGray);
designdata = d;
type = sel;
convmatrix = Matrix(1);
markers = 0;
if (sel == SelXY) {
} else if (sel == SelZX) {
convmatrix.v[1] = Vector(0.0, 0.0, -1.0);
convmatrix.v[2] = Vector(0.0, 1.0, 0.0);
} else if (sel == SelYZ) {
convmatrix.v[0] = Vector(0.0, 0.0, 1.0);
convmatrix.v[1] = Vector(1.0, 0.0, 0.0);
convmatrix.v[2] = Vector(0.0, 1.0, 0.0);
} else {
}
Attr.X = x;
Attr.Y = y;
Attr.W = w;
Attr.H = h;
}
TWinDisplay::~TWinDisplay ()
{
Destroy();
// INSERT>> デストラクタ用のコードはここに
}
static void getpoint(Matrix& mat, TPoint& pc, TPoint& vx, TPoint& vy, TPoint& vz, int& zx, int& zy, int& zz)
{
vx = TPoint(int(mat.v[0].x),-int(mat.v[0].y));
vy = TPoint(int(mat.v[1].x),-int(mat.v[1].y));
vz = TPoint(int(mat.v[2].x),-int(mat.v[2].y));
pc = TPoint(int(mat.v[3].x),-int(mat.v[3].y));
zx = int(mat.v[0].z);
zy = int(mat.v[1].z);
zz = int(mat.v[2].z);
}
static void draw5line(TDC& dc, TPoint& center, TPoint& offset, TPoint& p1, TPoint& p2)
{
dc.MoveTo(center+offset+p1-p2);
dc.LineTo(center-offset+p1-p2);
dc.LineTo(center-offset-p1+p2);
dc.LineTo(center+offset-p1+p2);
dc.LineTo(center+offset+p1-p2);
dc.MoveTo(center+offset+p1+p2);
dc.LineTo(center-offset+p1+p2);
dc.SelectObject(TPen(cBackGround,1,PS_DOT));
dc.MoveTo(center+offset+p1); dc.LineTo(center-offset+p1);
dc.MoveTo(center+offset+p2); dc.LineTo(center-offset+p2);
dc.MoveTo(center+p1-p2); dc.LineTo(center-p1+p2);
}
static void draw4line(TDC& dc, TPoint& center, TPoint& p1, TPoint& p2)
{
dc.MoveTo(center+p1+p2);
dc.LineTo(center+p1-p2);
dc.LineTo(center-p1-p2);
dc.LineTo(center-p1+p2);
dc.LineTo(center+p1+p2);
dc.SelectObject(TPen(cBackGround,1,PS_DOT));
dc.MoveTo(center+p1); dc.LineTo(center-p1);
dc.MoveTo(center+p2); dc.LineTo(center-p2);
}
static void draw9line(TDC& dc, TPoint& pc, TPoint& p1, TPoint& p2, TPoint& p3)
{
dc.MoveTo(pc+p1+p2+p3);
dc.LineTo(pc+p1+p2-p3);
dc.LineTo(pc+p1-p2-p3);
dc.LineTo(pc+p1-p2+p3);
dc.LineTo(pc-p1-p2+p3);
dc.LineTo(pc-p1+p2+p3);
dc.LineTo(pc-p1+p2-p3);
dc.LineTo(pc+p1+p2-p3);
dc.MoveTo(pc-p1+p2+p3);
dc.LineTo(pc+p1+p2+p3);
dc.LineTo(pc+p1-p2+p3);
dc.SelectObject(TPen(cBackGround,1,PS_DOT));
dc.MoveTo(pc+p1-p2); dc.LineTo(pc+p1+p2); dc.LineTo(pc-p1+p2);
dc.MoveTo(pc+p2-p3); dc.LineTo(pc+p2+p3); dc.LineTo(pc-p2+p3);
dc.MoveTo(pc+p3-p1); dc.LineTo(pc+p3+p1); dc.LineTo(pc-p3+p1);
}
#if 0
static int sign(int num, int weight)
{
if (num < 0) {
return -weight;
} else if (num > 0) {
return weight;
} else {
return 0;
}
}
static int sign(double num)
{
if (num < 0.0) {
return -1;
} else if (num > 0.0) {
return 1;
}
return 0;
}
#endif
void TWinDisplay::Set4Marker(SelectType type, TPoint& pc, TPoint& p1, TPoint& p2)
{
markers = 0;
markerpoint[markers] = pc;
markertype[markers++] = SelMove;
SelectType t1, t2;
if (type == SelXY) {
t1 = SelX;
t2 = SelY;
} else if (type == SelYZ) {
t1 = SelY;
t2 = SelZ;
} else {
t1 = SelZ;
t2 = SelX;
}
if (designdata->dragtype != DragRotOnly) {
markerpoint[markers] = pc + p1; markertype[markers++] = SelScale | t1;
markerpoint[markers] = pc - p1; markertype[markers++] = SelScale | t1;
markerpoint[markers] = pc + p2; markertype[markers++] = SelScale | t2;
markerpoint[markers] = pc - p2; markertype[markers++] = SelScale | t2;
}
if (designdata->dragtype != DragRotOnly) {
markerpoint[markers] = pc + p1 + p2; markertype[markers++] = SelRot | type;
markerpoint[markers] = pc + p1 - p2; markertype[markers++] = SelRot | type;
markerpoint[markers] = pc - p1 + p2; markertype[markers++] = SelRot | type;
markerpoint[markers] = pc - p1 - p2; markertype[markers++] = SelRot | type;
}
}
void TWinDisplay::Set5Marker(SelectType t3, SelectType /*t1*/, SelectType t2, TPoint& pc, TPoint& p3, TPoint& /*p1*/, TPoint& p2)
{
markers = 0;
markerpoint[markers] = pc;
markertype[markers++] = SelMove;
if (designdata->dragtype != DragRotOnly) {
markerpoint[markers] = pc + p2; markertype[markers++] = SelScale | t2;
markerpoint[markers] = pc + p3; markertype[markers++] = SelScale | t3;
markerpoint[markers] = pc - p3; markertype[markers++] = SelScale | t3;
}
if (designdata->dragtype != DragScaleOnly) {
markerpoint[markers] = pc + p2 + p3; markertype[markers++] = SelRot | t2 | t3;
markerpoint[markers] = pc + p2 - p3; markertype[markers++] = SelRot | t2 | t3;
}
}
void TWinDisplay::Set9Marker(SelectType t, TPoint& pc, TPoint& /*p1*/, TPoint& p2, TPoint& p3)
{
markers = 0;
markerpoint[markers] = pc;
markertype[markers++] = SelMove;
SelectType /*t1, */t2, t3;
if (t == SelX) {
// t1 = SelX;
t2 = SelY;
t3 = SelZ;
} else if (t == SelY) {
// t1 = SelY;
t2 = SelZ;
t3 = SelX;
} else {
// t1 = SelZ;
t2 = SelX;
t3 = SelY;
}
if (designdata->dragtype != DragRotOnly) {
markerpoint[markers] = pc + p2; markertype[markers++] = SelScale | t2;
markerpoint[markers] = pc + p3; markertype[markers++] = SelScale | t3;
// markerpoint[markers] = pc + p1 - p2; markertype[markers++] = SelScale | t2;
// markerpoint[markers] = pc + p1 - p3; markertype[markers++] = SelScale | t3;
}
if (designdata->dragtype != DragScaleOnly) {
// markerpoint[markers] = pc + p1 - p2 - p3; markertype[markers++] = SelRot | t2 | t3;
markerpoint[markers] = pc + p2 + p3; markertype[markers++] = SelRot | t2 | t3;
markerpoint[markers] = pc + p2 - p3; markertype[markers++] = SelRot | t2 | t3;
markerpoint[markers] = pc - p2 + p3; markertype[markers++] = SelRot | t2 | t3;
}
}
void TWinDisplay::DrawMarker(TDC& dc)
{
for (int i = markers-1; i >= 0; --i) {
switch (markertype[i] & SelMode) {
case SelMove: case SelTarget:
dc.SelectObject(TPen(cMarkerMove));
dc.SelectObject(TBrush(cMarkerMove));
break;
case SelRot:
dc.SelectObject(TPen(cMarkerRot));
dc.SelectObject(TBrush(cMarkerRot));
break;
case SelScale:
dc.SelectObject(TPen(cMarkerScale));
dc.SelectObject(TBrush(cMarkerScale));
break;
}
dc.Rectangle( markerpoint[i].x - markersize,
markerpoint[i].y - markersize,
markerpoint[i].x + markersize,
markerpoint[i].y + markersize);
}
}
void TWinDisplay::ShowCamera(Matrix& m, int flag)
{
Matrix mat;
mat = convmatrix * m;
TClientDC dc(*this);
// dc.SetROP2(R2_NOT);
dc.SetROP2(R2_XORPEN);
TPoint pc, vx, vy, vz;
int zx, zy, zz;
getpoint(mat, pc, vx, vy, vz, zx, zy, zz);
pc.x += Attr.W/2;
pc.y += Attr.H/2;
dc.SelectObject(TPen(cWireCameraSelect));
dc.MoveTo(pc); dc.LineTo(pc+vx);
if (vy.x == 0 && vy.y == 0) {
dc.MoveTo(pc); dc.LineTo(pc+vx+vz);
dc.MoveTo(pc); dc.LineTo(pc+vx-vz);
} else if (vz.x == 0 && vz.y == 0) {
dc.MoveTo(pc); dc.LineTo(pc+vx+vy);
dc.MoveTo(pc); dc.LineTo(pc+vx-vy);
} else {
dc.MoveTo(pc); dc.LineTo(pc+vx+vy+vz);
dc.MoveTo(pc); dc.LineTo(pc+vx+vy-vz);
dc.MoveTo(pc); dc.LineTo(pc+vx-vy+vz);
dc.MoveTo(pc); dc.LineTo(pc+vx-vy-vz);
}
if (flag) {
dc.SetROP2(R2_COPYPEN);
// DrawMarker(dc);
markers = 0;
markerpoint[markers] = pc;
markertype[markers++] = SelMove;
markerpoint[markers] = pc+vx;
markertype[markers++] = SelTarget;
DrawMarker(dc);
}
}
void TWinDisplay::ShowCube(Matrix& m, int flag, SelectType t)
{
//logprintf("ShowCube:\n");
//logprintf("(%6.3lf %6.3lf %6.3lf %6.3lf)\n", m.v[0].x, m.v[1].x, m.v[2].x, m.v[3].x);
//logprintf("(%6.3lf %6.3lf %6.3lf %6.3lf)\n", m.v[0].y, m.v[1].y, m.v[2].y, m.v[3].y);
//logprintf("(%6.3lf %6.3lf %6.3lf %6.3lf)\n", m.v[0].z, m.v[1].z, m.v[2].z, m.v[3].z);
Matrix mat;
mat = convmatrix * m;
TClientDC dc(*this);
// dc.SetROP2(R2_NOT);
// dc.SetROP2(R2_XORPEN);
// dc.SelectObject(TPen(cWireCube));
dc.SetROP2(R2_NOTXORPEN);
dc.SelectObject(TPen(cBackGround));
dc.SetBkMode(TRANSPARENT);
TPoint pc, vx, vy, vz;
int zx, zy, zz;
getpoint(mat, pc, vx, vy, vz, zx, zy, zz);
pc.x += Attr.W/2;
pc.y += Attr.H/2;
if (zx < 0) vx = -vx;
if (zy < 0) vy = -vy;
if (zz < 0) vz = -vz;
if (-minimumcube <= zx && zx <= minimumcube) {
if (-minimumcube <= zy && zy <= minimumcube) {
draw4line(dc, pc, vx, vy);
} else if (-minimumcube <= zz && zz <= minimumcube) {
draw4line(dc, pc, vz, vx);
} else {
draw5line(dc, pc, vx, vy, vz);
}
} else if (-minimumcube <= zy && zy <= minimumcube) {
if (-minimumcube <= zz && zz <= minimumcube) {
draw4line(dc, pc, vy, vz);
} else {
draw5line(dc, pc, vy, vz, vx);
}
} else if (-minimumcube <= zz && zz <= minimumcube) {
draw5line(dc, pc, vz, vx, vy);
} else {
draw9line(dc, pc, vx, vy, vz);
}
if (flag) {
if (-minimummarker <= zx && zx <= minimummarker) {
if (-minimummarker <= zy && zy <= minimummarker) {
Set4Marker(SelXY, pc, vx, vy);
} else if (-minimummarker <= zz && zz <= minimummarker) {
Set4Marker(SelZX, pc, vz, vx);
} else {
if (t & SelZ) {
Set5Marker(SelX, SelZ, SelY, pc, vx, vz, vy);
} else {
Set5Marker(SelX, SelY, SelZ, pc, vx, vy, vz);
}
}
} else if (-minimummarker <= zy && zy <= minimummarker) {
if (-minimummarker <= zz && zz <= minimummarker) {
Set4Marker(SelYZ, pc, vy, vz);
} else {
if (t & SelZ) {
Set5Marker(SelY, SelZ, SelX, pc, vy, vz, vx);
} else {
Set5Marker(SelY, SelX, SelZ, pc, vy, vx, vz);
}
}
} else if (-minimummarker <= zz && zz <= minimummarker) {
if (t & SelY) {
Set5Marker(SelZ, SelY, SelX, pc, vz, vy, vx);
} else {
Set5Marker(SelZ, SelX, SelY, pc, vz, vx, vy);
}
} else {
if (t & SelX) {
Set9Marker(SelX, pc, vx, vy, vz);
} else if (t & SelY) {
Set9Marker(SelY, pc, vy, vz, vx);
} else {
Set9Marker(SelZ, pc, vz, vx, vy);
}
}
#if 0
if (designdata->select == designdata->combined) {
int i, j;
for(i = j = 0; i < markers; i++) {
if ((markertype[i] & SelScale) == 0) {
if (i != j) {
markerpoint[j] = markerpoint[i];
markertype[j] = markertype[i];
}
j++;
}
}
markers = j;
}
#endif
dc.SetROP2(R2_COPYPEN);
DrawMarker(dc);
}
}
int TWinDisplay::GetPositionDistance(Parts *parts, TPoint &point)
{
int cx, cy;
cx = Attr.W / 2;
cy = Attr.H / 2;
Matrix m = designdata->GetMatrix(parts);
TPoint p(0,0);
if ( type == SelXY) {
p.x = cx + m.v[3].x;
p.y = cy - m.v[3].y;
} else if (type == SelYZ) {
p.x = cx + m.v[3].y;
p.y = cy - m.v[3].z;
} else if (type == SelZX) {
p.x = cx + m.v[3].x;
p.y = cy - m.v[3].z;
}
int distance;
if (p.x < point.x) {
distance = point.x - p.x;
} else {
distance = p.x - point.x;
}
if (p.y < point.y) {
distance += point.y - p.y;
} else {
distance += p.y - point.y;
}
return distance;
}
static int distance(TPoint& p1, TPoint& p2)
{
int dist;
TPoint p = p1 - p2;
if (p.x < 0) {
dist = -p.x;
} else {
dist = p.x;
}
if (p.y < 0) {
dist += -p.y;
} else {
dist += p.y;
}
return dist;
}
void TWinDisplay::Paint (TDC& dc, BOOL erase, TRect& rect)
{
TWindow::Paint(dc, erase, rect);
// INSERT>> 追加のコードはここに
SelectType t;
if (type == SelYZ) {
t = SelX;
} else if (type == SelZX) {
t = SelY;
} else {
t = SelZ;
}
designdata->Redraw(t);
#if 0
if (type == SelYZ) {
dc.TextOut(0,0,"前");
} else if (type == SelZX) {
dc.TextOut(0,0,"横");
} else {
dc.TextOut(0,0,"上");
}
#endif
}
void TWinDisplay::EvLButtonDown (UINT modKeys, TPoint& point)
{
TWindow::EvLButtonDown(modKeys, point);
// INSERT>> 追加コードはここに
if (designdata->zoommode == ZoomSelect) {
Zoom(modKeys, point);
return;
}
designdata->selectstatus = SelMode;
designdata->drag_point = point;
SetCapture();
}
void TWinDisplay::OpSelect(UINT /*modKeys*/, TPoint& point, Vector& /*v*/)
{
for (int i = 0; i < markers; ++i) {
if (distance(designdata->drag_point, markerpoint[i]) < markersize * 2) {
break;
}
}
if (i < markers) {
double rx, ry, len;
designdata->selectstatus = markertype[i];
designdata->GetCubeMatrix(designdata->select, designdata->drag_move, designdata->drag_rot, designdata->drag_scale);
designdata->drag_mat = designdata->drag_move * designdata->drag_rot * designdata->drag_scale;
switch (markertype[i] & SelMode) {
case SelRot:
if ((markertype[i] & SelXYZ) == SelNone) {
designdata->selectstatus = SelRot;
rx = double( point.y - markerpoint[0].y);
ry = double(-point.x + markerpoint[0].x);
if (type == SelZX) {
rx = -rx;
ry = -ry;
}
} else if (markertype[i] == (SelRot | SelX) || markertype[i] == (SelRot | SelY) || markertype[i] == (SelRot | SelZ)){
Matrix m = designdata->drag_mat;
m.v[0] -= m.v[3];
m.v[1] -= m.v[3];
m.v[2] -= m.v[3];
if (designdata->drag_scale.v[0].x < 0.0) m.v[0] = -1.0 * m.v[0];
if (designdata->drag_scale.v[1].y < 0.0) m.v[1] = -1.0 * m.v[1];
if (designdata->drag_scale.v[2].z < 0.0) m.v[2] = -1.0 * m.v[2];
m = convmatrix * m;
Vector v;
switch (markertype[i] & SelXYZ) {
case SelX: v = m.v[0]; break;
case SelY: v = m.v[1]; break;
case SelZ: v = m.v[2]; break;
}
rx = v.y;
ry = v.x;
} else {
Matrix m = convmatrix * designdata->drag_rot;
Vector v;
rx = designdata->drag_px[0] = (double)(point.x - markerpoint[0].x);
ry = designdata->drag_px[1] = (double)(point.y - markerpoint[0].y);
switch (markertype[i] & SelXYZ) {
case SelYZ: v = m.v[0]; break;
case SelZX: v = m.v[1]; break;
case SelXY: v = m.v[2]; break;
}
#if 0
switch (markertype[i] & SelXYZ) {
case SelYZ: logprintf("SelYZ:\n"); break;
case SelZX: logprintf("SelZX:\n"); break;
case SelXY: logprintf("SelXY:\n"); break;
}
logprintf("(%6.3lf %6.3lf):(%6.3lf)\n", rx, ry, v.z);
#endif
if (v.z > 0.0) {
designdata->drag_py[0] = designdata->drag_px[1];
designdata->drag_py[1] = -designdata->drag_px[0];
} else {
designdata->drag_py[0] = -designdata->drag_px[1];
designdata->drag_py[1] = designdata->drag_px[0];
}
designdata->drag_point = markerpoint[0];
}
len = rx*rx+ry*ry;
designdata->drag_rx = rx / len * deg(90.0);
designdata->drag_ry = ry / len * deg(90.0);
break;
case SelScale:
designdata->drag_point = markerpoint[0];
rx = double(point.x - markerpoint[0].x);
ry = double(point.y - markerpoint[0].y);
len = rx * rx + ry * ry;
designdata->drag_rx = rx / len;
designdata->drag_ry = ry / len;
break;
}
}
}
void TWinDisplay::OpSelectMove(UINT /*modKeys*/, TPoint& point, Vector& /*v*/)
{
Parts *p = NULL;;
for (p = designdata->parts; p != NULL; p = p -> next) {
if (GetPositionDistance(p, point) < markersize*3) {
break;
}
}
if (p == NULL && GetPositionDistance(designdata->camera, point) < markersize*3) {
p = designdata->camera;
}
if (p != NULL) {
designdata->SelectParts(p);
designdata->Redraw();
designdata->selectstatus = SelMove;
designdata->GetCubeMatrix(designdata->select, designdata->drag_move, designdata->drag_rot, designdata->drag_scale);
designdata->drag_mat = designdata->drag_move * designdata->drag_rot * designdata->drag_scale;
}
}
void TWinDisplay::DisplayCursorObject(UINT /*modKeys*/, TPoint& point)
{
Parts *p;
for (p = designdata->parts; p != NULL; p = p->next) {
if (GetPositionDistance(p, point) < markersize*2) {
break;
}
}
if (p == NULL && GetPositionDistance(designdata->camera, point) < markersize*2) {
p = designdata->camera;
}
designdata->Status->DisplayStatusTemp(p);
}
static void SelectOne(Vector& v)
{
double px, py, pz;
if ((px = v.x) < 0.0) px = -px;
if ((py = v.y) < 0.0) py = -py;
if ((pz = v.z) < 0.0) pz = -pz;
if (px > py && px > pz) {
v.y = v.z = 0.0;
} else if (py > pz) {
v.x = v.z = 0.0;
} else {
v.x = v.y = 0.0;
}
}
static void engrid(Vector& v, int grid)
{
if (v.x > 0) {
v.x = (double)( ((long)( v.x) + grid/2) / grid) * (double) grid;
} else {
v.x = -(double)( ((long)(-v.x) + grid/2) / grid) * (double) grid;
}
if (v.y > 0) {
v.y = (double)( ((long)( v.y) + grid/2) / grid) * (double) grid;
} else {
v.y = -(double)( ((long)(-v.y) + grid/2) / grid) * (double) grid;
}
if (v.z > 0) {
v.z = (double)( ((long)( v.z) + grid/2) / grid) * (double) grid;
} else {
v.z = -(double)( ((long)(-v.z) + grid/2) / grid) * (double) grid;
}
}
static void limit(Vector& v)
{
if (v.x > limitdim) v.x = limitdim;
if (v.x < -limitdim) v.x = -limitdim;
if (v.y > limitdim) v.y = limitdim;
if (v.y < -limitdim) v.y = -limitdim;
if (v.z > limitdim) v.z = limitdim;
if (v.z < -limitdim) v.z = -limitdim;
}
void TWinDisplay::OpDrag(UINT modKeys, TPoint& point, Vector& v)
{
Matrix nmat;
Vector tmpvec;
double r;
double px, py;
switch (designdata->selectstatus & SelMode) {
case SelMove:
if (modKeys & MK_SHIFT) {
SelectOne(v);
}
tmpvec = designdata->select->position + (1.0/designdata->displayscale)*v;
limit(tmpvec);
if (((modKeys & MK_CONTROL) != 0) ^ (designdata->gridflag != FALSE)) {
engrid(tmpvec, designdata->gridspacing);
if (v.x == 0.0) tmpvec.x = designdata->select->position.x;
if (v.y == 0.0) tmpvec.y = designdata->select->position.y;
if (v.z == 0.0) tmpvec.z = designdata->select->position.z;
}
if (designdata->select == designdata->camera) {
nmat = (designdata->camera->target - tmpvec) ^ Vector(0,0,1);
{
double l0x = (designdata->camera->target - tmpvec).length();
double l0y = l0x*tan(designdata->camera->angle/2.0);
double l0z = l0y * 3 / 4;
nmat = designdata->drag_move.move(tmpvec-designdata->select->position)
* nmat * Matrix::m_scale(Vector(l0x, l0y, l0z));
}
} else {
nmat = designdata->drag_move.move(tmpvec-designdata->select->position)
* designdata->drag_rot * designdata->drag_scale;
}
designdata->Status->DisplayPosition(tmpvec);
designdata->ShowCube(designdata->drag_mat, nmat);
designdata->drag_mat = nmat;
break;
case SelTarget:
if (modKeys & MK_SHIFT) {
SelectOne(v);
}
tmpvec = designdata->camera->target + (1.0/designdata->displayscale) * v;
limit(tmpvec);
if (((modKeys & MK_CONTROL) != 0) ^ (designdata->gridflag != FALSE)) {
engrid(tmpvec, designdata->gridspacing);
if (v.x == 0.0) tmpvec.x = designdata->camera->target.x;
if (v.y == 0.0) tmpvec.y = designdata->camera->target.y;
if (v.z == 0.0) tmpvec.z = designdata->camera->target.z;
}
nmat = (tmpvec - designdata->camera->position) ^ Vector(0.0, 0.0, 1.0);
{
double l0x = (tmpvec - designdata->camera->position).length();
double l0y = l0x*tan(designdata->camera->angle/2.0);
double l0z = l0y * 3 / 4;
nmat = designdata->drag_move * nmat * Matrix::m_scale(Vector(l0x, l0y, l0z));
}
designdata->Status->DisplayTarget(tmpvec);
designdata->ShowCube(designdata->drag_mat, nmat);
designdata->drag_mat = nmat;
break;
case SelRot:
r = designdata->drag_rx * (point.x - designdata->drag_point.x)
+ designdata->drag_ry * (point.y - designdata->drag_point.y);
switch (designdata->selectstatus & SelXYZ) {
case SelNone:
switch (type) {
case SelXY: nmat = Matrix(1).rotz(r); break;
case SelYZ: nmat = Matrix(1).rotx(r); break;
case SelZX: nmat = Matrix(1).roty(r); break;
}
nmat = nmat * designdata->drag_rot;
break;
case SelX: nmat = designdata->drag_rot.rotx(r); break;
case SelY: nmat = designdata->drag_rot.roty(r); break;
case SelZ: nmat = designdata->drag_rot.rotz(r); break;
case SelXY:
px = designdata->drag_px[0] * (point.x - designdata->drag_point.x)
+ designdata->drag_px[1] * (point.y - designdata->drag_point.y);
py = designdata->drag_py[0] * (point.x - designdata->drag_point.x)
+ designdata->drag_py[1] * (point.y - designdata->drag_point.y);
if (-minimumdouble < px && px < minimumdouble
&& -minimumdouble < py && py < minimumdouble) {
nmat = designdata->drag_rot;
} else {
nmat = designdata->drag_rot.rotz(atan2(py, px));
}
break;
case SelYZ:
px = designdata->drag_px[0] * (point.x - designdata->drag_point.x)
+ designdata->drag_px[1] * (point.y - designdata->drag_point.y);
py = designdata->drag_py[0] * (point.x - designdata->drag_point.x)
+ designdata->drag_py[1] * (point.y - designdata->drag_point.y);
if (-minimumdouble < px && px < minimumdouble
&& -minimumdouble < py && py < minimumdouble) {
nmat = designdata->drag_rot;
} else {
nmat = designdata->drag_rot.rotx(atan2(py, px));
}
break;
case SelZX:
px = designdata->drag_px[0] * (point.x - designdata->drag_point.x)
+ designdata->drag_px[1] * (point.y - designdata->drag_point.y);
py = designdata->drag_py[0] * (point.x - designdata->drag_point.x)
+ designdata->drag_py[1] * (point.y - designdata->drag_point.y);
if (-minimumdouble < px && px < minimumdouble
&& -minimumdouble < py && py < minimumdouble) {
nmat = designdata->drag_rot;
} else {
nmat = designdata->drag_rot.roty(atan2(py, px));
}
break;
}
tmpvec = nmat.GetRotation();
if (((modKeys & MK_CONTROL) != 0) ^ (designdata->gridflag != FALSE)) {
tmpvec *= rad(1.0);
engrid(tmpvec, designdata->rotspacing);
tmpvec *= deg(1.0);
nmat = Matrix(1).rotz(tmpvec.z).roty(tmpvec.y).rotx(tmpvec.x);
}
nmat = designdata->drag_move * nmat * designdata->drag_scale;
designdata->Status->DisplayRotation(tmpvec);
designdata->ShowCube(designdata->drag_mat, nmat);
designdata->drag_mat = nmat;
break;
case SelScale:
r = designdata->drag_rx * (point.x - designdata->drag_point.x)
+ designdata->drag_ry * (point.y - designdata->drag_point.y);
tmpvec = designdata->select->scale;
nmat = Matrix(1);
if ((modKeys & MK_SHIFT) || designdata->select == designdata->combined) {
nmat.v[0].x = nmat.v[1].y = nmat.v[2].z = r;
tmpvec *= r;
} else {
if (designdata->selectstatus & SelX) { nmat.v[0].x = r; tmpvec.x *= r;}
if (designdata->selectstatus & SelY) { nmat.v[1].y = r; tmpvec.y *= r;}
if (designdata->selectstatus & SelZ) { nmat.v[2].z = r; tmpvec.z *= r;}
}
if (((modKeys & MK_CONTROL) != 0) ^ (designdata->gridflag != FALSE)) {
Vector org = tmpvec;
tmpvec *= scalespacingfactor;
engrid(tmpvec, designdata->scalespacing);
tmpvec *= (1.0/scalespacingfactor);
if ((modKeys & MK_SHIFT) == 0 && designdata->select != designdata->combined) {
if ((designdata->selectstatus & SelX)==0) tmpvec.x = org.x;
if ((designdata->selectstatus & SelY)==0) tmpvec.y = org.y;
if ((designdata->selectstatus & SelZ)==0) tmpvec.z = org.z;
}
if (org.x != 0.0) nmat.v[0].x *= tmpvec.x / org.x;
if (org.y != 0.0) nmat.v[1].y *= tmpvec.y / org.y;
if (org.z != 0.0) nmat.v[2].z *= tmpvec.z / org.z;
}
nmat = designdata->drag_move * designdata->drag_rot * designdata->drag_scale * nmat;
designdata->ShowCube(designdata->drag_mat, nmat);
designdata->drag_mat = nmat;
designdata->Status->DisplayScale(tmpvec);
break;
case SelCombined:
{
TClientDC dc(*this);
dc.SetROP2(R2_NOTXORPEN);
dc.SelectObject(TPen(cBackGround));
dc.MoveTo(designdata->tmp_point.x, designdata->tmp_point.y);
dc.LineTo(designdata->tmp_point.x, designdata->drag_point.y);
dc.LineTo(designdata->drag_point.x, designdata->drag_point.y);
dc.LineTo(designdata->drag_point.x, designdata->tmp_point.y);
dc.LineTo(designdata->tmp_point.x, designdata->tmp_point.y);
dc.MoveTo(point.x, point.y);
dc.LineTo(point.x, designdata->drag_point.y);
dc.LineTo(designdata->drag_point.x, designdata->drag_point.y);
dc.LineTo(designdata->drag_point.x, point.y);
dc.LineTo(point.x, point.y);
designdata->tmp_point = point;
}
break;
}
}
void TWinDisplay::EvMouseMove (UINT modKeys, TPoint& point)
{
TWindow::EvMouseMove(modKeys, point);
// INSERT>> 追加コードはここに
if (designdata->selectstatus == SelNone) {
if (designdata->select == NULL) {
DisplayCursorObject(modKeys, point);
}
return;
}
Vector v;
if (type == SelXY) {
v.x = double(point.x - designdata->drag_point.x);
v.y = -double(point.y - designdata->drag_point.y);
v.z = 0.0;
} else if (type == SelYZ) {
v.x = 0.0;
v.y= double(point.x - designdata->drag_point.x);
v.z = -double(point.y - designdata->drag_point.y);
} else {
v.x = double(point.x - designdata->drag_point.x);
v.y = 0.0;
v.z = -double(point.y - designdata->drag_point.y);
}
if (designdata->selectstatus == SelMode && designdata->select != NULL) {
OpSelect(modKeys, point, v);
}
if (designdata->selectstatus == SelMode) {
OpSelectMove(modKeys, point, v);
}
if (designdata->selectstatus == SelMode) {
// designdata->selectstatus = SelNone;
designdata->selectstatus = SelCombined;
designdata->tmp_point = designdata->drag_point;
}
OpDrag(modKeys, point, v);
}
void TWinDisplay::OpSelectObject(UINT /*modKeys*/, TPoint& point)
{
const int maxSelObj=128;
const int maxSelDist=markersize*10;
Parts *sel[maxSelObj];
int dis[maxSelObj];
int d, i, count = 0;
Parts *p;
for (p = designdata->parts; p != NULL; p = p->next) {
if ((d = GetPositionDistance(p,point)) < maxSelDist) {
if (count < maxSelObj || dis[count-1] > d) {
if (count < maxSelObj) {
count++;
}
for (i = count-1; i > 0; --i) {
if (dis[i-1] < d) {
break;
}
dis[i] = dis[i-1];
sel[i] = sel[i-1];
}
dis[i] = d;
sel[i] = p;
}
}
}
if ((d = GetPositionDistance(designdata->camera, point)) < maxSelDist) {
if (count < maxSelObj || dis[count-1] > d) {
if (count < maxSelObj) {
count++;
}
for (i = count-1; i > 0; --i) {
if (dis[i-1] < d) {
break;
}
dis[i] = dis[i-1];
sel[i] = sel[i-1];
}
dis[i] = d;
sel[i] = designdata->camera;
}
}
Parts *selp = NULL;
if (count > 0) {
if (designdata->select == NULL) {
selp = sel[0];
} else {
for (i = 0; i < count-1; ++i) {
if (sel[i] == designdata->select) {
selp = sel[i+1];
break;
}
}
if (i == count-1) {
selp = sel[0];
}
}
}
if (selp != NULL && designdata->select != selp) {
designdata->SelectParts(selp);
designdata->Redraw();
}
#if 0
Parts *p, *selp = NULL, *first = NULL;
for (p = designdata->parts; p != NULL; p = p -> next) {
if (GetPositionDistance(p, point) < markersize*3) {
if (first == NULL) {
first = p;
}
if (selp == designdata->select) {
selp = p;
break;
}
selp = p;
}
}
if (p == NULL) {
if (GetPositionDistance(designdata->camera, point) < markersize*3) {
if (first == NULL) {
first = designdata->camera;
}
selp = designdata->camera;
}
}
if (designdata->select == NULL || selp == designdata->select) {
selp = first;
}
if (selp != NULL && designdata->select != selp) {
designdata->SelectParts(selp);
designdata->Redraw();
}
#endif
}
void TWinDisplay::EvLButtonUp (UINT modKeys, TPoint& point)
{
TWindow::EvLButtonUp(modKeys, point);
// INSERT>> 追加コードはここに
ReleaseCapture();
if (designdata->selectstatus == SelNone) {
return;
}
Vector v;
if (type == SelXY) {
v.x = double(point.x - designdata->drag_point.x);
v.y = -double(point.y - designdata->drag_point.y);
v.z = 0.0;
} else if (type == SelYZ) {
v.x = 0.0;
v.y= double(point.x - designdata->drag_point.x);
v.z = -double(point.y - designdata->drag_point.y);
} else {
v.x = double(point.x - designdata->drag_point.x);
v.y = 0.0;
v.z = -double(point.y - designdata->drag_point.y);
}
Vector tmpvec;
switch (designdata->selectstatus & SelMode) {
case SelMode:
OpSelectObject(modKeys, point);
break;
case SelMove:
if (modKeys & MK_SHIFT) {
SelectOne(v);
}
tmpvec = designdata->select->position;
designdata->select->position += (1.0/designdata->displayscale) * v;
limit(designdata->select->position);
if (((modKeys & MK_CONTROL) != 0) ^ (designdata->gridflag != FALSE)) {
engrid(designdata->select->position, designdata->gridspacing);
if (v.x == 0.0) designdata->select->position.x = tmpvec.x;
if (v.y == 0.0) designdata->select->position.y = tmpvec.y;
if (v.z == 0.0) designdata->select->position.z = tmpvec.z;
}
if (tmpvec != designdata->select->position) {
if (designdata->select == designdata->camera) {
designdata->camera->SetTarget(designdata->camera->target);
designdata->CalcPoints(designdata->select);
designdata->CalcViewAll();
} else {
designdata->CalcPoints(designdata->select);
}
if (designdata->select != designdata->camera) {
designdata->editflag++;
}
designdata->Redraw();
}
break;
case SelTarget:
if (modKeys & MK_SHIFT) {
SelectOne(v);
}
tmpvec = designdata->camera->target + (1.0 / designdata->displayscale) * v;
limit(tmpvec);
if (((modKeys & MK_CONTROL) != 0) ^ (designdata->gridflag != FALSE)) {
engrid(tmpvec, designdata->gridspacing);
if (v.x == 0.0) tmpvec.x = designdata->camera->target.x;
if (v.y == 0.0) tmpvec.y = designdata->camera->target.y;
if (v.z == 0.0) tmpvec.z = designdata->camera->target.z;
}
if (tmpvec != designdata->camera->target) {
designdata->camera->SetTarget(tmpvec);
designdata->CalcPoints(designdata->camera);
designdata->CalcViewAll();
// designdata->editflag++;
designdata->Redraw();
}
break;
case SelRot: {
double r;
double px, py;
Matrix nmat;
r = designdata->drag_rx * (point.x - designdata->drag_point.x)
+ designdata->drag_ry * (point.y - designdata->drag_point.y);
switch (designdata->selectstatus & SelXYZ) {
case SelNone:
switch (type) {
case SelXY: nmat = Matrix(1).rotz(r); break;
case SelYZ: nmat = Matrix(1).rotx(r); break;
case SelZX: nmat = Matrix(1).roty(r); break;
}
nmat = nmat * designdata->drag_rot;
break;
case SelX: nmat = designdata->drag_rot.rotx(r); break;
case SelY: nmat = designdata->drag_rot.roty(r); break;
case SelZ: nmat = designdata->drag_rot.rotz(r); break;
case SelXY:
px = designdata->drag_px[0] * (point.x - designdata->drag_point.x)
+ designdata->drag_px[1] * (point.y - designdata->drag_point.y);
py = designdata->drag_py[0] * (point.x - designdata->drag_point.x)
+ designdata->drag_py[1] * (point.y - designdata->drag_point.y);
if (-minimumdouble < px && px < minimumdouble
&& -minimumdouble < py && py < minimumdouble) {
nmat = designdata->drag_rot;
} else {
nmat = designdata->drag_rot.rotz(atan2(py, px));
}
break;
case SelYZ:
px = designdata->drag_px[0] * (point.x - designdata->drag_point.x)
+ designdata->drag_px[1] * (point.y - designdata->drag_point.y);
py = designdata->drag_py[0] * (point.x - designdata->drag_point.x)
+ designdata->drag_py[1] * (point.y - designdata->drag_point.y);
if (-minimumdouble < px && px < minimumdouble
&& -minimumdouble < py && py < minimumdouble) {
nmat = designdata->drag_rot;
} else {
nmat = designdata->drag_rot.rotx(atan2(py, px));
}
break;
case SelZX:
px = designdata->drag_px[0] * (point.x - designdata->drag_point.x)
+ designdata->drag_px[1] * (point.y - designdata->drag_point.y);
py = designdata->drag_py[0] * (point.x - designdata->drag_point.x)
+ designdata->drag_py[1] * (point.y - designdata->drag_point.y);
if (-minimumdouble < px && px < minimumdouble
&& -minimumdouble < py && py < minimumdouble) {
nmat = designdata->drag_rot;
} else {
nmat = designdata->drag_rot.roty(atan2(py, px));
}
break;
}
Vector tmprot = designdata->select->rotation;
designdata->select->SetRotationParameter(nmat);
if (((modKeys & MK_CONTROL) != 0) ^ (designdata->gridflag != FALSE)) {
Vector tmpvec = rad(1.0) * designdata->select->rotation;
engrid(tmpvec, designdata->rotspacing);
designdata->select->rotation = deg(1.0) * tmpvec;
}
if (tmprot != designdata->select->rotation) {
designdata->CalcPoints(designdata->select);
designdata->editflag++;
designdata->Redraw();
}
}
break;
case SelScale: {
double r;
r = designdata->drag_rx * (point.x - designdata->drag_point.x)
+ designdata->drag_ry * (point.y - designdata->drag_point.y);
Vector tmpvec = designdata->select->scale;
if ((modKeys & MK_SHIFT) || designdata->select == designdata->combined) {
tmpvec *= r;
} else {
if (designdata->selectstatus & SelX) tmpvec.x *= r;
if (designdata->selectstatus & SelY) tmpvec.y *= r;
if (designdata->selectstatus & SelZ) tmpvec.z *= r;
}
int redrawflag;
redrawflag = designdata->select->scale != tmpvec;
if (tmpvec.x > 10000.0) { tmpvec.x = 10000.0; redrawflag = TRUE; }
if (tmpvec.y > 10000.0) { tmpvec.y = 10000.0; redrawflag = TRUE; }
if (tmpvec.z > 10000.0) { tmpvec.z = 10000.0; redrawflag = TRUE; }
if (tmpvec.x < -10000.0) { tmpvec.x = -10000.0; redrawflag = TRUE; }
if (tmpvec.y < -10000.0) { tmpvec.y = -10000.0; redrawflag = TRUE; }
if (tmpvec.z < -10000.0) { tmpvec.z = -10000.0; redrawflag = TRUE; }
if (((modKeys & MK_CONTROL) != 0) ^ (designdata->gridflag != FALSE)) {
Vector ovec = tmpvec;
tmpvec *= scalespacingfactor;
engrid(tmpvec, designdata->scalespacing);
tmpvec *= (1.0/scalespacingfactor);
if ((modKeys & MK_SHIFT) == 0 && designdata->select != designdata->combined) {
if ((designdata->selectstatus & SelX)==0) tmpvec.x = ovec.x;
if ((designdata->selectstatus & SelY)==0) tmpvec.y = ovec.y;
if ((designdata->selectstatus & SelZ)==0) tmpvec.z = ovec.z;
}
}
if (tmpvec.x == 0.0 || tmpvec.y == 0.0 || tmpvec.z == 0.0) {
Matrix nmat = designdata->drag_move * designdata->drag_rot * designdata->drag_scale;
designdata->ShowCube(designdata->drag_mat, nmat);
designdata->Status->DisplayScale(designdata->select->scale);
} else if (redrawflag) {
designdata->select->scale = tmpvec;
designdata->CalcPoints(designdata->select);
designdata->Redraw();
designdata->editflag++;
}
}
break;
case SelCombined:
{
TClientDC dc(*this);
dc.SetROP2(R2_NOTXORPEN);
dc.SelectObject(TPen(cBackGround));
dc.MoveTo(point.x, point.y);
dc.LineTo(point.x, designdata->drag_point.y);
dc.LineTo(designdata->drag_point.x, designdata->drag_point.y);
dc.LineTo(designdata->drag_point.x, point.y);
dc.LineTo(point.x, point.y);
int x1, x2, y1, y2;
if (point.x < designdata->drag_point.x) {
x1 = point.x;
x2 = designdata->drag_point.x;
} else {
x1 = designdata->drag_point.x;
x2 = point.x;
}
if (point.y < designdata->drag_point.y) {
y1 = point.y;
y2 = designdata->drag_point.y;
} else {
y1 = designdata->drag_point.y;
y2 = point.y;
}
int oldnparts = designdata->combined->nparts;
designdata->combined->DeleteAllParts();
Matrix m = convmatrix * Matrix::m_move(designdata->displayoffset).scale(designdata->displayscale);
int px, py;
for (Parts *p = designdata->parts;p != NULL; p = p->next) {
Vector pos;
pos = m * p->position;
px = Attr.W/2 + pos.x;
py = Attr.H/2 - pos.y;
if (x1 <= px && px <= x2 && y1 <= py && py <= y2) {
designdata->combined->AddParts(p);
p->sel = TRUE;
} else {
p->sel = FALSE;
}
}
if (designdata->combined->nparts == 1) {
designdata->SelectParts(designdata->combined->parts[0]);
designdata->Redraw();
} else if (designdata->combined->nparts > 0) {
designdata->combined->CalcSizeAll();
designdata->SelectParts(designdata->combined);
designdata->Redraw();
} else {
designdata->combined->nparts = oldnparts;
}
}
break;
}
designdata->selectstatus = SelNone;
}
void TWinDisplay::EvRButtonDown (UINT modKeys, TPoint& point)
{
TWindow::EvRButtonDown(modKeys, point);
// INSERT>> 追加コードはここに
if (designdata->selectstatus != SelNone) {
designdata->selectstatus = SelNone;
designdata->Redraw();
} else if (designdata->select != NULL) {
designdata->SelectParts(NULL);
designdata->Redraw();
}
ReleaseCapture();
}
void TWinDisplay::ShowGrid(TDC& dc)
{
if (designdata->meshflag == FALSE) {
return;
}
Vector v = convmatrix * designdata->displayoffset;
double bx = - (1.0 / designdata->displayscale) * (v.x + Attr.W / 2);
double by = - (1.0 / designdata->displayscale) * (v.y + Attr.H / 2);
int cx = (1.0 / designdata->displayscale) * Attr.W / designdata->meshspacing+1;
int cy = (1.0 / designdata->displayscale) * Attr.H / designdata->meshspacing+1;
// TClientDC dc(*this);
dc.SelectObject(TPen(cGrid));
dc.SelectObject(TPen(cGrid,1,PS_DOT));
dc.SetBkMode(TRANSPARENT);
// dc.SelectObject(TBrush(cBackGround));
int i;
if (bx < 0) {
bx = -((long)(-bx)/designdata->meshspacing) * designdata->meshspacing;
} else {
bx = ((long)( bx)/designdata->meshspacing) * designdata->meshspacing;
}
for (i = 0; i < cx; ++i) {
int x = bx * designdata->displayscale + v.x + Attr.W / 2;
if (-designdata->meshspacing/2 < bx && bx < designdata->meshspacing/2) {
dc.SelectObject(TPen(cGridZero));
dc.MoveTo(x,0);
dc.LineTo(x,Attr.H);
dc.SelectObject(TPen(cGrid,1,PS_DOT));
// dc.SelectObject(TPen(cGrid));
} else {
dc.MoveTo(x,0);
dc.LineTo(x,Attr.H);
}
bx += designdata->meshspacing;
}
if (by < 0) {
by = -((long)(-by)/designdata->meshspacing) * designdata->meshspacing;
} else {
by = ((long)( by)/designdata->meshspacing) * designdata->meshspacing;
}
for (i = 0; i < cy; ++i) {
int y = -by * designdata->displayscale - v.y + Attr.H / 2;
if (-designdata->meshspacing/2 < by && by < designdata->meshspacing/2) {
dc.SelectObject(TPen(cGridZero));
dc.MoveTo(0,y);
dc.LineTo(Attr.W,y);
dc.SelectObject(TPen(cGrid,1,PS_DOT));
// dc.SelectObject(TPen(cGrid));
} else {
dc.MoveTo(0,y);
dc.LineTo(Attr.W,y);
}
by += designdata->meshspacing;
}
}
void TWinDisplay::Zoom(UINT /*modKeys*/, TPoint& point)
{
Vector v;
if (type == SelXY) {
v.x = double(point.x - Attr.W/2);
v.y = -double(point.y - Attr.H/2);
v.z = 0.0;
} else if (type == SelYZ) {
v.x = 0.0;
v.y= double(point.x - Attr.W/2);
v.z = -double(point.y - Attr.H/2);
} else {
v.x = double(point.x - Attr.W/2);
v.y = 0.0;
v.z = -double(point.y - Attr.H/2);
}
designdata->displayoffset -= v;
designdata->displayscale *= 4;
designdata->displayoffset = 4 * designdata->displayoffset;
designdata->SetScrollLimit(TRUE);
designdata->zoommode = ZoomNow;
designdata->Redraw(SelXYZ | SelStat, TRUE);
}
void TWinDisplay::ShowObject(TDC& dc, Parts *p)
{
Matrix m = designdata->GetMatrix(p);
int i = 0;
int begin, end = -1;
int cx, cy;
cx = Attr.W / 2;
cy = Attr.H / 2;
int combflag = (designdata->combined == designdata->select);
if (p == designdata->select || (combflag && p->sel)) {
dc.SelectObject(TPen(cWireSelect));
} else if (p == designdata->camera) {
if (designdata->select != NULL) {
dc.SelectObject(TPen(cWireCameraNoSelect));
} else {
dc.SelectObject(TPen(cWireCamera));
}
} else {
if (designdata->select != NULL) {
dc.SelectObject(TPen(cWireNoSelect));
} else {
dc.SelectObject(TPen(cWireNormal));
}
}
int *ppx, *ppy;
switch(type) {
case SelYZ:
ppx = p->point_y;
ppy = p->point_z;
break;
case SelZX:
ppx = p->point_x;
ppy = p->point_z;
break;
case SelXY:
ppx = p->point_x;
ppy = p->point_y;
break;
}
for (; i < p->lines; ++i) {
if ((begin = p->line_1[i]) != end) {
dc.MoveTo(cx + ppx[begin], cy - ppy[begin]);
}
end = p->line_2[i];
dc.LineTo(cx + ppx[end], cy - ppy[end]);
}
if (designdata->select == NULL) {
dc.SelectObject(TPen(cMarker));
dc.SelectObject(TBrush(cMarker));
switch(type) {
case SelYZ:
dc.Rectangle(cx+m.v[3].y-markersize, cy-m.v[3].z-markersize,
cx+m.v[3].y+markersize, cy-m.v[3].z+markersize);
break;
case SelZX:
dc.Rectangle(cx+m.v[3].x-markersize, cy-m.v[3].z-markersize,
cx+m.v[3].x+markersize, cy-m.v[3].z+markersize);
break;
case SelXY:
dc.Rectangle(cx+m.v[3].x-markersize, cy-m.v[3].y-markersize,
cx+m.v[3].x+markersize, cy-m.v[3].y+markersize);
break;
}
}
}
void TWinDisplay::Redraw(void)
{
#if 0
TClientDC cdc(*this);
TMemoryDC dc(cdc);
TBitmap bitmap(cdc, Attr.W, Attr.H);
dc.SelectObject(bitmap);
#else
TClientDC dc(*this);
#endif
dc.SelectObject(TPen(cBackGround));
dc.SelectObject(TBrush(cBackGround));
dc.Rectangle(dc.GetClipBox());
ShowGrid(dc);
dc.SetBkColor(cBackGround);
dc.SetTextColor(TColor::White);
if (type == SelXY) {
dc.TextOut(0,0,"上");
} else if (type == SelZX) {
dc.TextOut(0,0,"横");
} else {
dc.TextOut(0,0,"前");
}
for (Parts *p = designdata->parts; p != NULL; p = p->next) {
if (p != designdata->select) {
ShowObject(dc, p);
}
}
if (designdata->camera != designdata->select) {
ShowObject(dc, designdata->camera);
if (designdata->select != NULL) {
ShowObject(dc, designdata->select);
}
}
#if 0
cdc.BitBlt(0,0,Attr.W, Attr.H, dc, 0, 0, SRCCOPY);
#endif
}