1/* IPLine3D.m
2 * 3-D Line Inspector
3 *
4 * Copyright (C) 1995-2003 by vhf interservice GmbH
5 * Author:   Georg Fleischmann
6 *
7 * created:  2002-08-20
8 * modified: 2003-06-26
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the vhf Public License as
12 * published by vhf interservice GmbH. Among other things, the
13 * License requires that the copyright notices and this notice
14 * be preserved on all copies.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 * See the vhf Public License for more details.
20 *
21 * You should have received a copy of the vhf Public License along
22 * with this program; see the file LICENSE. If not, write to vhf.
23 *
24 * vhf interservice GmbH, Im Marxle 3, 72119 Altingen, Germany
25 * eMail: info@vhf.de
26 * http://www.vhf.de
27 */
28
29#include "../App.h"
30#include "../DocView.h"
31#include "../Graphics.h"
32#include "../LayerObject.h"
33#include "InspectorPanel.h"
34#include "IPLine3D.h"
35
36@implementation IPLine3D
37
38- (void)update:sender
39{   VGraphic	*g = sender;
40    NSPoint	p;
41    float	zv0, zv1;
42    id		view = [self view];
43
44    [graphic release];
45    graphic = [sender retain];
46
47    [super update:sender];
48    [(VLine3D*)g getZLevel:&zv0 :&zv1];
49    p = [view pointRelativeOrigin:[g pointWithNum:0]];
50    [xField setStringValue:buildRoundedString(convertToUnit(p.x), LARGENEG_COORD, LARGE_COORD)];
51    [yField setStringValue:buildRoundedString(convertToUnit(p.y), LARGENEG_COORD, LARGE_COORD)];
52    [zField setStringValue:buildRoundedString(convertToUnit(zv0), LARGENEG_COORD, LARGE_COORD)];
53
54    [lengthField setStringValue:buildRoundedString(convertToUnit([g length]), LARGENEG_COORD, LARGE_COORD)];
55
56    p = [view pointRelativeOrigin:[g pointWithNum:1]];
57    [endXField setStringValue:buildRoundedString(convertToUnit(p.x), LARGENEG_COORD, LARGE_COORD)];
58    [endYField setStringValue:buildRoundedString(convertToUnit(p.y), LARGENEG_COORD, LARGE_COORD)];
59    [endZField setStringValue:buildRoundedString(convertToUnit(zv1), LARGENEG_COORD, LARGE_COORD)];
60}
61
62- (void)setEndX:(id)sender
63{   float	min = LARGENEG_COORD, max = LARGE_COORD;
64    float	v = [endXField floatValue];
65    BOOL	control = [(App*)NSApp control];
66
67    if ([sender isKindOfClass:[NSButton class]])
68        switch ([sender tag])
69        {
70            case BUTTONLEFT:	v -= ((control) ? 10.0 : 1.0); break;
71            case BUTTONRIGHT:	v += ((control) ? 10.0 : 1.0);
72        }
73
74    if (v < min) v = min;
75    if (v > max) v = max;
76    //[endXField setStringValue:vhfStringWithFloat(v)];
77
78    v = convertFromUnit(v);
79    [[self view] movePoint:1 to:[[self view] pointAbsolute:NSMakePoint(v, 0.0)] x:YES y:NO all:NO];
80    [self update:graphic];
81}
82
83- (void)setEndY:(id)sender
84{   float	min = LARGENEG_COORD, max = LARGE_COORD;
85    float	v = [endYField floatValue];
86    BOOL	control = [(App*)NSApp control];
87
88    if ([sender isKindOfClass:[NSButton class]])
89        switch ([sender tag])
90        {
91            case BUTTONLEFT:	v -= ((control) ? 10.0 : 1.0); break;
92            case BUTTONRIGHT:	v += ((control) ? 10.0 : 1.0);
93        }
94
95    if (v < min) v = min;
96    if (v > max) v = max;
97    //[endYField setStringValue:vhfStringWithFloat(v)];
98
99    v = convertFromUnit(v);
100    [[self view] movePoint:1 to:[[self view] pointAbsolute:NSMakePoint(0.0, v)] x:NO y:YES all:NO];
101    [self update:graphic];
102}
103
104- (void)setEndZ:(id)sender
105{   int		l, cnt, i;
106    id		slayList = [[self view] slayList];
107    float	min = LARGENEG_COORD, max = LARGE_COORD;
108    float	v = [endZField floatValue];
109    BOOL	control = [(App*)NSApp control];
110
111    if ([sender isKindOfClass:[NSButton class]])
112        switch ([sender tag])
113        {
114            case BUTTONLEFT:	v -= ((control) ? 10.0 : 1.0); break;
115            case BUTTONRIGHT:	v += ((control) ? 10.0 : 1.0);
116        }
117
118    if (v < min)	v = min;
119    if (v > max)	v = max;
120    //[endZField setStringValue:vhfStringWithFloat(v)];
121
122    v = convertFromUnit(v);
123
124    /* set z level of all objects */
125    cnt = [slayList count];
126    for (l=0; l<cnt; l++)
127    {	NSMutableArray *slist = [slayList objectAtIndex:l];
128
129        if (![[[[self view] layerList] objectAtIndex:l] editable])
130            continue;
131        for (i=[slist count]-1; i>=0; i--)
132        {   id	g = [slist objectAtIndex:i];
133
134            if ([g isMemberOfClass:[VLine3D class]]) // [g respondsToSelector:@selector(setZLevel:)]
135            {   float	zv0, zv1;
136
137                [(VLine3D*)g getZLevel:&zv0 :&zv1];
138                [(VLine3D*)g setZLevel:zv0 :v];
139                [[[self view] document] setDirty:YES];
140            }
141        }
142    }
143
144    [[self view] drawAndDisplay];
145    [self update:graphic];
146}
147
148- (void)setLength:(id)sender
149{   float	min = 0.0, max = LARGE_COORD;
150    float	v = [lengthField floatValue];
151    BOOL	control = [(App*)NSApp control];
152
153    if ( [sender isKindOfClass:[NSButton class]] )
154        switch ( [sender tag] )
155        {
156            case BUTTONLEFT:	v -= ((control) ? 1.0 : 0.1); break;
157            case BUTTONRIGHT:	v += ((control) ? 1.0 : 0.1);
158        }
159
160    if (v < min)	v = min;
161    if (v > max)	v = max;
162    //[lengthField setStringValue:vhfStringWithFloat(v)];
163
164    v = convertFromUnit(v);
165    [[self view] takeLength:v];
166    [self update:graphic];
167}
168
169- (void)setLock:(id)sender
170{
171}
172
173- (void)setPointX:(id)sender
174{   float	min = LARGENEG_COORD, max = LARGE_COORD;
175    float	v = [xField floatValue];
176    BOOL	control = [(App*)NSApp control];
177
178    if ([sender isKindOfClass:[NSButton class]])
179    {
180        switch ([sender tag])
181        {
182            case BUTTONLEFT:	v -= ((control) ? 10.0 : 1.0); break;
183            case BUTTONRIGHT:	v += ((control) ? 10.0 : 1.0);
184        }
185    }
186
187    if (v < min)	v = min;
188    if (v > max)	v = max;
189    //[xField setStringValue:vhfStringWithFloat(v)];
190
191    v = convertFromUnit(v);
192    [[self view] movePoint:0 to:[[self view] pointAbsolute:NSMakePoint(v, 0.0)] x:YES y:NO all:NO];
193    [self update:graphic];
194}
195
196- (void)setPointY:(id)sender
197{   float	min = LARGENEG_COORD, max = LARGE_COORD;
198    float	v = [yField floatValue];
199    BOOL	control = [(App*)NSApp control];
200
201    if ([sender isKindOfClass:[NSButton class]])
202    {
203        switch ([sender tag])
204        {
205            case BUTTONLEFT:	v -= ((control) ? 10.0 : 1.0); break;
206            case BUTTONRIGHT:	v += ((control) ? 10.0 : 1.0);
207        }
208    }
209
210    if (v < min)	v = min;
211    if (v > max)	v = max;
212    //[yField setStringValue:vhfStringWithFloat(v)];
213
214    v = convertFromUnit(v);
215    [[self view] movePoint:0 to:[[self view] pointAbsolute:NSMakePoint(0.0, v)] x:NO y:YES all:NO];
216    [self update:graphic];
217}
218
219- (void)setPointZ:(id)sender
220{   int		l, cnt, i;
221    id		slayList = [[self view] slayList];
222    float	min = LARGENEG_COORD, max = LARGE_COORD;
223    float	v = [zField floatValue];
224    BOOL	control = [(App*)NSApp control];
225
226    if ([sender isKindOfClass:[NSButton class]])
227        switch ([sender tag])
228        {
229            case BUTTONLEFT:	v -= ((control) ? 10.0 : 1.0); break;
230            case BUTTONRIGHT:	v += ((control) ? 10.0 : 1.0);
231        }
232
233    if (v < min)	v = min;
234    if (v > max)	v = max;
235
236    v = convertFromUnit(v);
237
238    /* set z level of all objects */
239    cnt = [slayList count];
240    for (l=0; l<cnt; l++)
241    {	NSMutableArray *slist = [slayList objectAtIndex:l];
242
243        if (![[[[self view] layerList] objectAtIndex:l] editable])
244            continue;
245        for (i=[slist count]-1; i>=0; i--)
246        {   id	g = [slist objectAtIndex:i];
247
248            if ([g isMemberOfClass:[VLine3D class]])
249            {   float	zv0, zv1;
250
251                [(VLine3D*)g getZLevel:&zv0 :&zv1];
252                [(VLine3D*)g setZLevel:v :zv1];
253                [[[self view] document] setDirty:YES];
254            }
255        }
256    }
257    [[self view] drawAndDisplay];
258    [self update:graphic];
259}
260
261- (void)displayWillEnd
262{
263}
264
265@end
266