~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/Mod/Sketcher/Gui/ViewProviderSketchSF.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam C. Powell, IV
  • Date: 2010-01-11 08:48:33 UTC
  • mfrom: (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20100111084833-4g9vgdqbkw8u34zb
Tags: 0.9.2646.5-1
* New upstream version (closes: #561696).
* Added swig to Build-Depends (closes: #563523, #563772).
* Removed python-opencv from Build-Depends and Recommends (closes: #560768).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (c) 2009 J�rgen Riegel <juergen.riegel@web.de>              *
 
3
 *                                                                         *
 
4
 *   This file is part of the FreeCAD CAx development system.              *
 
5
 *                                                                         *
 
6
 *   This library is free software; you can redistribute it and/or         *
 
7
 *   modify it under the terms of the GNU Library General Public           *
 
8
 *   License as published by the Free Software Foundation; either          *
 
9
 *   version 2 of the License, or (at your option) any later version.      *
 
10
 *                                                                         *
 
11
 *   This library  is distributed in the hope that it will be useful,      *
 
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
14
 *   GNU Library General Public License for more details.                  *
 
15
 *                                                                         *
 
16
 *   You should have received a copy of the GNU Library General Public     *
 
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
 
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
 
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
 
20
 *                                                                         *
 
21
 ***************************************************************************/
 
22
 
 
23
 
 
24
#include "PreCompiled.h"
 
25
 
 
26
#ifndef _PreComp_
 
27
# include <Standard_math.hxx>
 
28
# include <Inventor/SoPath.h>
 
29
# include <Inventor/SoPickedPoint.h>
 
30
# include <Inventor/details/SoLineDetail.h>
 
31
# include <Inventor/details/SoPointDetail.h>
 
32
# include <Inventor/nodes/SoBaseColor.h>
 
33
# include <Inventor/nodes/SoCoordinate3.h>
 
34
# include <Inventor/nodes/SoDrawStyle.h>
 
35
# include <Inventor/nodes/SoLineSet.h>
 
36
# include <Inventor/nodes/SoPointSet.h>
 
37
# include <Inventor/nodes/SoMaterial.h>
 
38
# include <Inventor/nodes/SoSeparator.h>
 
39
# include <Inventor/nodes/SoVertexProperty.h>
 
40
# include <QMessageBox>
 
41
#endif
 
42
 
 
43
/// Here the FreeCAD includes sorted by Base,App,Gui......
 
44
#include <Base/Parameter.h>
 
45
#include <Base/Console.h>
 
46
#include <Gui/Application.h>
 
47
#include <Gui/Document.h>
 
48
#include <Gui/MainWindow.h>
 
49
#include <Gui/DlgEditFileIncludeProptertyExternal.h>
 
50
 
 
51
#include <Mod/Sketcher/App/SketchFlatInterface.h>
 
52
#include <Mod/Sketcher/App/SketchObjectSF.h>
 
53
 
 
54
 
 
55
#include "ViewProviderSketchSF.h"
 
56
 
 
57
 
 
58
using namespace SketcherGui;
 
59
using namespace Sketcher;
 
60
 
 
61
const float fCurveColor[] =     {1.0f,1.0f,1.0f}; 
 
62
const float fCurveConstructionColor[] = {0.2f,1.0f,0.2f}; 
 
63
const float fPointColor[] =             {0.9f,0.9f,0.9f}; 
 
64
const float fPreselectColor[] = {0.8f,0.0f,0.0f}; 
 
65
const float fSelectColor[] =    {1.0f,0.0f,0.0f}; 
 
66
const float fDatumLineColor[] = {0.0f,0.8f,0.0f}; 
 
67
 
 
68
//**************************************************************************
 
69
// Construction/Destruction
 
70
 
 
71
PROPERTY_SOURCE(SketcherGui::ViewProviderSketchSF, PartGui::ViewProvider2DObject)
 
72
 
 
73
 
 
74
ViewProviderSketchSF::ViewProviderSketchSF()
 
75
  : Mode(STATUS_NONE),DragPoint(-1),EditRoot(0)
 
76
{
 
77
        PointsMaterials = 0;
 
78
        LinesMaterials = 0;
 
79
        CurvesMaterials = 0;
 
80
        PointsCoordinate = 0;
 
81
        LinesCoordinate = 0;
 
82
        CurvesCoordinate = 0;
 
83
        LineSet = 0;
 
84
        CurveSet = 0;
 
85
    PointSet = 0;
 
86
 
 
87
    PreselectCurve = -1;
 
88
    PreselectPoint = -1;
 
89
 
 
90
    sPixmap = "Sketcher_NewSketch";
 
91
}
 
92
 
 
93
ViewProviderSketchSF::~ViewProviderSketchSF()
 
94
{
 
95
 
 
96
}
 
97
 
 
98
 
 
99
// **********************************************************************************
 
100
 
 
101
void ViewProviderSketchSF::setSketchMode(int mode)
 
102
{
 
103
        Mode = mode;
 
104
}
 
105
 
 
106
bool ViewProviderSketchSF::setConstrainOnSelected(int Constrain)
 
107
{
 
108
        return false;
 
109
}
 
110
 
 
111
bool ViewProviderSketchSF::keyPressed(int key)
 
112
{
 
113
        return true;
 
114
}
 
115
 
 
116
void ViewProviderSketchSF::getCoordsOnSketchPlane(double &u, double &v,const SbVec3f &point, const SbVec3f &normal)
 
117
{
 
118
        // Plane form
 
119
        Base::Vector3d R0(0,0,0),RN(0,0,1),RX(1,0,0),RY(0,1,0);
 
120
 
 
121
    // move to position of Sketch
 
122
    Base::Placement Plz = getSketchObjectSF()->Placement.getValue();
 
123
    R0 = Plz.getPosition() ; 
 
124
        Base::Rotation tmp(Plz.getRotation());
 
125
    tmp.multVec(RN,RN);
 
126
    tmp.multVec(RX,RX);
 
127
    tmp.multVec(RY,RY);
 
128
        Plz.setRotation(tmp);
 
129
 
 
130
        // line 
 
131
        Base::Vector3d R1(point[0],point[1],point[2]),RA(normal[0],normal[1],normal[2]);
 
132
        // intersection point on plane
 
133
        Base::Vector3d S = R1 + ((RN * (R0-R1))/(RN*RA))*RA;
 
134
 
 
135
        // distance to x Axle of the sketch
 
136
        S.TransformToCoordinateSystem(R0,RX,RY);
 
137
 
 
138
        u = S.x;
 
139
        v = S.y;
 
140
}
 
141
 
 
142
bool ViewProviderSketchSF::mouseButtonPressed(int Button, bool pressed, const SbVec3f &point,
 
143
                                            const SbVec3f &normal, const SoPickedPoint* pp)
 
144
{
 
145
    double x,y;
 
146
    SbVec3f pos = point;
 
147
    if (pp) {
 
148
        const SoDetail* detail = pp->getDetail();
 
149
        if (detail && detail->getTypeId() == SoPointDetail::getClassTypeId()) {
 
150
            pos = pp->getPoint();
 
151
        }
 
152
    }
 
153
 
 
154
        getCoordsOnSketchPlane(x,y,pos,normal);
 
155
 
 
156
        // Left Mouse button ****************************************************
 
157
        if (Button == 1) {
 
158
                if (pressed) {
 
159
                        // Do things depending on the mode of the user interaction
 
160
                        switch(Mode){
 
161
                                case STATUS_NONE:
 
162
                    if (PreselectPoint >=0) {
 
163
                        this->DragPoint = SketchFlat->getPoint(PreselectPoint);
 
164
                                                Base::Console().Log("start dragging, point:%d\n",this->DragPoint);
 
165
                                            SketchFlat->forcePoint(this->DragPoint,x,y);
 
166
                                            Mode = STATUS_SKETCH_DragPoint;
 
167
                        return true;
 
168
                    } else
 
169
                        return false;
 
170
 
 
171
                                case STATUS_SKETCH_CreateArc:
 
172
                                case STATUS_SKETCH_CreateCircle:
 
173
                                case STATUS_SKETCH_CreateRectangle:
 
174
                                case STATUS_SKETCH_CreateText:
 
175
                                        return true;
 
176
                                case STATUS_SKETCH_CreateLine:
 
177
                                        this->DragPoint = SketchFlat->addLine(x,y);
 
178
                                        SketchFlat->forcePoint(this->DragPoint,x,y);
 
179
                                        Mode = STATUS_SKETCH_DoLine;
 
180
                                        draw();
 
181
                                        return true;
 
182
                                case STATUS_SKETCH_DoLine:
 
183
                                        SketchFlat->forcePoint(this->DragPoint,x,y);
 
184
                                        SketchFlat->solve();
 
185
                                        draw();
 
186
                                        Base::Console().Log("Finish line, point:%d\n",this->DragPoint);
 
187
                    this->DragPoint = -1;
 
188
                                        Mode = STATUS_NONE;
 
189
                                        return true;
 
190
                                case STATUS_SKETCH_CreatePolyline:
 
191
                                        this->DragPoint = SketchFlat->addLine(x,y);
 
192
                                        SketchFlat->forcePoint(this->DragPoint,x,y);
 
193
                                        Mode = STATUS_SKETCH_DoPolyline;
 
194
                                        draw();
 
195
                                        return true;
 
196
                                case STATUS_SKETCH_DoPolyline:
 
197
                                        SketchFlat->forcePoint(this->DragPoint,x,y);
 
198
                                        SketchFlat->solve();
 
199
                                        this->DragPoint = SketchFlat->addLine(x,y);
 
200
                                        SketchFlat->forcePoint(this->DragPoint,x,y);
 
201
                                        draw();
 
202
                                        return true;
 
203
                default:
 
204
                    return false;
 
205
                                        
 
206
                        }
 
207
        }
 
208
        else {
 
209
                        // Do things depending on the mode of the user interaction
 
210
                        switch (Mode) {
 
211
                                case STATUS_SKETCH_DragPoint:
 
212
                                        SketchFlat->forcePoint(this->DragPoint,x,y);
 
213
                                        SketchFlat->solve();
 
214
                                        draw();
 
215
                    this->DragPoint = -1;
 
216
                                        Mode = STATUS_NONE;
 
217
                                        return true;
 
218
                default:
 
219
                    return false;
 
220
            }
 
221
        }
 
222
        }
 
223
    // Right mouse button ****************************************************
 
224
    else if (Button == 2) {
 
225
        if (pressed) {
 
226
            switch(Mode){
 
227
                case STATUS_SKETCH_DoPolyline:
 
228
                    SketchFlat->forcePoint(this->DragPoint,x,y);
 
229
                    SketchFlat->solve();
 
230
                    draw();
 
231
                    Base::Console().Log("Finish polyline, point:%d\n",this->DragPoint);
 
232
                    this->DragPoint = -1;
 
233
                    Mode = STATUS_NONE;
 
234
                    return true;
 
235
                default:
 
236
                    return false;
 
237
            }
 
238
        }
 
239
    }
 
240
 
 
241
        return false;
 
242
}
 
243
 
 
244
bool ViewProviderSketchSF::mouseMove(const SbVec3f &point, const SbVec3f &normal, const SoPickedPoint* pp)
 
245
{
 
246
        double x,y;
 
247
        getCoordsOnSketchPlane(x,y,point,normal);
 
248
 
 
249
    handlePreselection(pp);
 
250
 
 
251
        switch (Mode) {
 
252
                case STATUS_NONE:
 
253
                        return false;
 
254
                case STATUS_SKETCH_CreateArc:
 
255
                case STATUS_SKETCH_CreateCircle:
 
256
                case STATUS_SKETCH_CreatePolyline:
 
257
                case STATUS_SKETCH_CreateRectangle:
 
258
                case STATUS_SKETCH_CreateText:
 
259
                case STATUS_SKETCH_CreateLine:
 
260
                        return true;
 
261
                case STATUS_SKETCH_DoLine:
 
262
                case STATUS_SKETCH_DoPolyline:
 
263
                case STATUS_SKETCH_DragPoint:
 
264
                        SketchFlat->forcePoint(this->DragPoint,x,y);
 
265
                        SketchFlat->solve();
 
266
                        draw();
 
267
                        return true;
 
268
        }
 
269
 
 
270
        return false;
 
271
}
 
272
 
 
273
bool ViewProviderSketchSF::handlePreselection(const SoPickedPoint* Point)
 
274
{
 
275
    if (Point) {
 
276
        Base::Console().Log("Point pick\n");
 
277
        const SoDetail* point_detail = Point->getDetail(this->PointSet);
 
278
        if (point_detail && point_detail->getTypeId() == SoPointDetail::getClassTypeId()) {
 
279
            // get the index
 
280
            int idx = static_cast<const SoPointDetail*>(point_detail)->getCoordinateIndex();
 
281
            if (PreselectPoint != idx) {
 
282
                PointsMaterials->diffuseColor.set1Value(idx,fPreselectColor);
 
283
                if (PreselectPoint >= 0)
 
284
                    PointsMaterials->diffuseColor.set1Value(PreselectPoint,fPointColor);
 
285
                PreselectPoint = idx;
 
286
                if (PreselectCurve >= 0)
 
287
                    CurvesMaterials->diffuseColor.set1Value(PreselectCurve,PreselectOldColor);
 
288
                PreselectCurve = -1;
 
289
            }
 
290
 
 
291
            Base::Console().Log("Point pick%d\n",idx);
 
292
            return true;
 
293
        }
 
294
 
 
295
        const SoDetail* curve_detail = Point->getDetail(this->CurveSet);
 
296
        if (curve_detail && curve_detail->getTypeId() == SoLineDetail::getClassTypeId()) {
 
297
            // get the index
 
298
            int idx = static_cast<const SoLineDetail*>(curve_detail)->getLineIndex();
 
299
            if (PreselectCurve != idx) {
 
300
                if (PreselectCurve >= 0)
 
301
                    CurvesMaterials->diffuseColor.set1Value(PreselectCurve,PreselectOldColor);
 
302
                                PreselectOldColor = CurvesMaterials->diffuseColor[idx];
 
303
                CurvesMaterials->diffuseColor.set1Value(idx,fPreselectColor);
 
304
                PreselectCurve = idx;
 
305
                if (PreselectPoint >= 0)
 
306
                    PointsMaterials->diffuseColor.set1Value(PreselectPoint,fPointColor);
 
307
                PreselectPoint = -1;
 
308
            }
 
309
            
 
310
            Base::Console().Log("Curve pick%d\n",idx);
 
311
            return true;
 
312
        }
 
313
 
 
314
        const SoDetail* datum_detail = Point->getDetail(this->LineSet);
 
315
        if (datum_detail && datum_detail->getTypeId() == SoLineDetail::getClassTypeId()) {
 
316
            // get the index
 
317
            unsigned long idx = static_cast<const SoLineDetail*>(datum_detail)->getPartIndex();
 
318
            Base::Console().Log("Datum pick%d\n",idx);
 
319
            return true;
 
320
        }
 
321
    }
 
322
 
 
323
    if (PreselectCurve >= 0)
 
324
        CurvesMaterials->diffuseColor.set1Value(PreselectCurve,PreselectOldColor);
 
325
    PreselectCurve = -1;
 
326
    if (PreselectPoint >= 0)
 
327
        PointsMaterials->diffuseColor.set1Value(PreselectPoint,fPointColor);
 
328
    PreselectPoint = -1;
 
329
 
 
330
    return false;
 
331
}
 
332
 
 
333
bool ViewProviderSketchSF::isPointOnSketch(const SoPickedPoint* pp) const
 
334
{
 
335
    // checks if we picked a point on the sketch or any other nodes like the grid
 
336
    SoPath* path = pp->getPath();
 
337
    return path->containsNode(EditRoot);
 
338
}
 
339
 
 
340
bool ViewProviderSketchSF::doubleClicked(void)
 
341
{
 
342
 
 
343
    Sketcher::SketchObjectSF *obj = static_cast<Sketcher::SketchObjectSF *>(getObject());
 
344
 
 
345
        Gui::Dialog::DlgEditFileIncludePropertyExternal dlg((obj->SketchFlatFile),Gui::getMainWindow());
 
346
 
 
347
        dlg.ProcName = QString::fromUtf8((App::Application::Config()["AppHomePath"] + "bin/sketchflat.exe").c_str());
 
348
 
 
349
    if(dlg.Do() == 1)
 
350
        App::GetApplication().getActiveDocument()->recompute();
 
351
 
 
352
        //Gui::Application::Instance->activeDocument()->setEdit(this);
 
353
        return true;
 
354
}
 
355
 
 
356
void ViewProviderSketchSF::draw(void)
 
357
{
 
358
    double x,y;
 
359
    //double x0, y0, dx, dy;
 
360
    int i=0;
 
361
    //bool Construction;
 
362
    // sketchflat generate curves out of entities:
 
363
    //SketchFlat->setUpRendering();
 
364
 
 
365
    // go through the curves and collect the points
 
366
    //int NbrCrv = SketchFlat->nbrOfCurves();
 
367
    //int totalPts=0;
 
368
    //std::vector<std::vector<Base::Vector3d> > coords(NbrCrv);
 
369
    //for (i=0 ; i<NbrCrv;++i) {
 
370
    //    SketchFlat->getCurvePoints(coords[i],Construction,i);
 
371
    //    totalPts += coords[i].size();
 
372
    //}
 
373
 
 
374
    std::vector<Base::Vector3d> Coords;
 
375
    std::vector<unsigned int> Index;
 
376
    std::vector<unsigned int> Color;
 
377
 
 
378
    SketchFlat->getLineSet(Coords,Index,Color);
 
379
 
 
380
    CurveSet->numVertices.setNum(Index.size());
 
381
    CurvesCoordinate->point.setNum(Coords.size());
 
382
    CurvesMaterials->diffuseColor.setNum(Color.size());
 
383
 
 
384
    SbVec3f* verts = CurvesCoordinate->point.startEditing();
 
385
    int32_t* index = CurveSet->numVertices.startEditing();
 
386
    SbColor* color = CurvesMaterials->diffuseColor.startEditing();
 
387
 
 
388
    i=0;
 
389
    for(std::vector<Base::Vector3d>::const_iterator it=Coords.begin();it!=Coords.end();++it,i++){
 
390
        verts[i].setValue(it->x,it->y,0.1f);
 
391
    }
 
392
    i=0;
 
393
    for(std::vector<unsigned int>::const_iterator it=Index.begin();it!=Index.end();++it,i++){
 
394
        index[i]=*it;
 
395
    }
 
396
    i=0;
 
397
    for(std::vector<unsigned int>::const_iterator it=Color.begin();it!=Color.end();++it,i++){
 
398
        color[i].setValue((*it==1?fCurveConstructionColor:fCurveColor));
 
399
    }
 
400
 
 
401
    CurvesCoordinate->point.finishEditing();
 
402
    CurveSet->numVertices.finishEditing();
 
403
    CurvesMaterials->diffuseColor.finishEditing();
 
404
 
 
405
    //if (NbrCrv > 0) {
 
406
    //    // use the start/finish editing facility for optimization
 
407
    //    SbVec3f* verts = CurvesCoordinate->point.startEditing();
 
408
    //    int32_t* index = CurveSet->numVertices.startEditing();
 
409
    //    SbColor* color = CurvesMaterials->diffuseColor.startEditing();
 
410
 
 
411
    //    for (i=0 ; i<NbrCrv;++i) {
 
412
    //        const std::vector<Base::Vector3d>& c = coords[i];
 
413
    //        for (std::vector<Base::Vector3d>::const_iterator it = c.begin(); it != c.end(); ++it)
 
414
    //            verts[r++].setValue(it->x,it->y,0.1f);
 
415
    //        index[i] = c.size();
 
416
    //        color[i].setValue((Construction?fCurveConstructionColor:fCurveColor));
 
417
    //    }
 
418
    //    CurvesCoordinate->point.finishEditing();
 
419
    //    CurveSet->numVertices.finishEditing();
 
420
    //    CurvesMaterials->diffuseColor.finishEditing();
 
421
    //}
 
422
 
 
423
    //// set up datum lines
 
424
    //int NbrLns = SketchFlat->nbrOfLines();
 
425
    //LinesCoordinate->point.setNum(2*NbrLns);
 
426
    //LinesMaterials->diffuseColor.setNum(NbrLns);
 
427
    //LineSet->numVertices.setNum(NbrLns);
 
428
    //if (NbrLns > 0) {
 
429
    //    // use the start/finish editing facility for optimization
 
430
    //    SbVec3f* verts = LinesCoordinate->point.startEditing();
 
431
    //    int32_t* index = LineSet->numVertices.startEditing();
 
432
    //    SbColor* color = LinesMaterials->diffuseColor.startEditing();
 
433
    //    for (i=0; i<NbrLns; ++i) {
 
434
    //        SketchFlat->getLine(i, x0, y0, dx, dy);
 
435
    //        verts[i*2  ].setValue(x0-dx*50,y0-dy*50,0.1f);
 
436
    //        verts[i*2+1].setValue(x0+dx*50,y0+dy*50,0.1f);
 
437
    //        index[i] = 2;
 
438
    //        color[i].setValue(fDatumLineColor);
 
439
    //    }
 
440
    //    LinesCoordinate->point.finishEditing();
 
441
    //    LineSet->numVertices.finishEditing();
 
442
    //    LinesMaterials->diffuseColor.finishEditing();
 
443
    //}
 
444
 
 
445
    // set up the points
 
446
    int NbrPts = SketchFlat->nbrOfPoints();
 
447
    PointsCoordinate->point.setNum(NbrPts);
 
448
    PointsMaterials->diffuseColor.setNum(NbrPts);
 
449
    if (NbrPts > 0) {
 
450
        // use the start/finish editing facility for optimization
 
451
        SbVec3f* verts = PointsCoordinate->point.startEditing();
 
452
        SbColor* color = PointsMaterials->diffuseColor.startEditing();
 
453
        for (i=0; i<NbrPts; ++i) {
 
454
            SketchFlat->getPoint(i,x,y);
 
455
            verts[i].setValue(x,y,0.2f);
 
456
            color[i].setValue(fPointColor);
 
457
        }
 
458
        if (PreselectPoint >= 0 && PreselectPoint < NbrPts)
 
459
            color[PreselectPoint].setValue(fPreselectColor);
 
460
        PointsCoordinate->point.finishEditing();
 
461
        PointsMaterials->diffuseColor.finishEditing();
 
462
    }
 
463
}
 
464
 
 
465
void ViewProviderSketchSF::updateData(const App::Property* prop)
 
466
{
 
467
    ViewProvider2DObject::updateData(prop);
 
468
}
 
469
 
 
470
void ViewProviderSketchSF::onChanged(const App::Property* prop)
 
471
{
 
472
    // call father
 
473
    PartGui::ViewProvider2DObject::onChanged(prop);
 
474
}
 
475
 
 
476
void ViewProviderSketchSF::attach(App::DocumentObject *pcFeat)
 
477
{
 
478
    ViewProviderPart::attach(pcFeat);
 
479
}
 
480
 
 
481
bool ViewProviderSketchSF::setEdit(int ModNum)
 
482
{
 
483
 
 
484
 
 
485
 //   if (SketchFlatInterface::isAlive()) {
 
486
 //       QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Cannot edit sketch"),
 
487
 //           QObject::tr("Sketch cannot be edited because there is already another sketch in edit mode.\n"
 
488
 //           "Please leave the edit mode for the other sketch to enter edit mode for this sketch."));
 
489
 //       return false;
 
490
 //   }
 
491
 
 
492
 //   // interface to the solver
 
493
        //SketchFlat = new SketchFlatInterface();
 
494
 
 
495
 //   // insert the SketchFlat file
 
496
 //   SketchFlat->load(getSketchObjectSF()->SketchFlatFile.getValue());
 
497
 
 
498
 //   createEditInventorNodes();
 
499
 //   this->hide(); // avoid that the wires interfere with the edit lines
 
500
 
 
501
        //ShowGrid.setValue(true);
 
502
 
 
503
 //   SketchFlat->solve();
 
504
        //draw();
 
505
 
 
506
        return true;
 
507
}
 
508
 
 
509
void ViewProviderSketchSF::createEditInventorNodes(void)
 
510
{
 
511
        if (!EditRoot) {
 
512
                EditRoot = new SoSeparator;
 
513
                pcRoot->addChild(EditRoot);
 
514
        EditRoot->renderCaching = SoSeparator::OFF ;
 
515
        }
 
516
 
 
517
        // stuff for the points ++++++++++++++++++++++++++++++++++++++
 
518
    PointsMaterials = new SoMaterial;
 
519
        EditRoot->addChild(PointsMaterials);
 
520
 
 
521
        SoMaterialBinding *MtlBind = new SoMaterialBinding;
 
522
        MtlBind->value = SoMaterialBinding::PER_VERTEX;
 
523
        EditRoot->addChild(MtlBind);
 
524
 
 
525
        PointsCoordinate = new SoCoordinate3;
 
526
        EditRoot->addChild(PointsCoordinate);
 
527
 
 
528
        SoDrawStyle *DrawStyle = new SoDrawStyle;
 
529
        DrawStyle->pointSize = 6;
 
530
        EditRoot->addChild( DrawStyle );
 
531
    PointSet = new SoPointSet;
 
532
        EditRoot->addChild( PointSet );
 
533
 
 
534
        // stuff for the lines +++++++++++++++++++++++++++++++++++++++
 
535
    LinesMaterials = new SoMaterial;
 
536
        EditRoot->addChild(LinesMaterials);
 
537
 
 
538
        MtlBind = new SoMaterialBinding;
 
539
        MtlBind->value = SoMaterialBinding::PER_PART;
 
540
        EditRoot->addChild(MtlBind);
 
541
 
 
542
        LinesCoordinate = new SoCoordinate3;
 
543
        EditRoot->addChild(LinesCoordinate);
 
544
 
 
545
        DrawStyle = new SoDrawStyle;
 
546
        DrawStyle->lineWidth = 3;
 
547
        DrawStyle->linePattern = 0x0fff;
 
548
        EditRoot->addChild(DrawStyle);
 
549
 
 
550
        LineSet = new SoLineSet;
 
551
 
 
552
        EditRoot->addChild(LineSet);
 
553
 
 
554
        // stuff for the Curves +++++++++++++++++++++++++++++++++++++++
 
555
    CurvesMaterials = new SoMaterial;
 
556
        EditRoot->addChild(CurvesMaterials);
 
557
 
 
558
        MtlBind = new SoMaterialBinding;
 
559
        MtlBind->value = SoMaterialBinding::PER_FACE;
 
560
        EditRoot->addChild(MtlBind);
 
561
 
 
562
        CurvesCoordinate = new SoCoordinate3;
 
563
        EditRoot->addChild(CurvesCoordinate);
 
564
 
 
565
        DrawStyle = new SoDrawStyle;
 
566
        DrawStyle->lineWidth = 3;
 
567
        EditRoot->addChild( DrawStyle );
 
568
 
 
569
        CurveSet = new SoLineSet;
 
570
 
 
571
        EditRoot->addChild( CurveSet );
 
572
}
 
573
 
 
574
void ViewProviderSketchSF::unsetEdit(void)
 
575
{
 
576
        //ShowGrid.setValue(false);
 
577
 
 
578
 //   std::string file;
 
579
 
 
580
 //   // save the result of editing
 
581
 //   if (std::string(getSketchObjectSF()->SketchFlatFile.getValue())=="") {
 
582
 //       // make a meaningfull name
 
583
 //       Base::FileInfo temp(getSketchObjectSF()->SketchFlatFile.getDocTransientPath()
 
584
 //                           + "/" + getSketchObjectSF()->getNameInDocument() + ".skf");
 
585
 //       if (temp.exists())
 
586
 //           // save under save name
 
587
 //           file = Base::FileInfo::getTempFileName("Sketch.skf",getSketchObjectSF()
 
588
 //                           ->SketchFlatFile.getDocTransientPath().c_str());
 
589
 //       else
 
590
 //           file = temp.filePath();
 
591
 //   }
 
592
 //   else {
 
593
 //       // save under old name
 
594
 //       file = getSketchObjectSF()->SketchFlatFile.getExchangeTempFile();
 
595
 //   }
 
596
 
 
597
 //   // save the sketch and set the property
 
598
 //   SketchFlat->save(file.c_str());
 
599
 //   getSketchObjectSF()->SketchFlatFile.setValue(file.c_str());
 
600
 //   getSketchObjectSF()->touch();
 
601
 
 
602
        //// close the solver
 
603
        //delete(SketchFlat);
 
604
 
 
605
 //   // recompute the part
 
606
 //   getSketchObjectSF()->getDocument()->recompute();
 
607
 
 
608
        //// empty the nodes
 
609
        //EditRoot->removeAllChildren();
 
610
        //PointsMaterials = 0;
 
611
        //LinesMaterials = 0;
 
612
        //CurvesMaterials = 0;
 
613
        //PointsCoordinate = 0;
 
614
        //LinesCoordinate = 0;
 
615
        //CurvesCoordinate = 0;
 
616
        //LineSet = 0;
 
617
        //CurveSet = 0;
 
618
 //   PointSet = 0;
 
619
 
 
620
 //   PreselectCurve = -1;
 
621
 //   PreselectPoint = -1;
 
622
 //   this->show();
 
623
}
 
624
 
 
625
Sketcher::SketchObjectSF* ViewProviderSketchSF::getSketchObjectSF(void)
 
626
{
 
627
    return dynamic_cast<Sketcher::SketchObjectSF*>(pcObject);
 
628
}