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

« back to all changes in this revision

Viewing changes to src/App/FeatureTest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-07-16 18:37:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090716183741-oww9kcxqrk991i1n
Tags: upstream-0.8.2237
Import upstream version 0.8.2237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (c) J�rgen Riegel          (juergen.riegel@web.de) 2002     *
 
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
#ifndef _PreComp_
 
26
#endif
 
27
 
 
28
 
 
29
#include <Base/Console.h>
 
30
#include <Base/Exception.h>
 
31
#include "FeatureTest.h"
 
32
#include "Material.h"
 
33
 
 
34
#define new DEBUG_CLIENTBLOCK
 
35
using namespace App;
 
36
 
 
37
 
 
38
PROPERTY_SOURCE(App::FeatureTest, App::DocumentObject)
 
39
 
 
40
const char* enums[]= {"Zero","One","Two","Three","Four",NULL};
 
41
const PropertyIntegerConstraint::Constraints intPercent = {0,100,1};
 
42
const PropertyFloatConstraint::Constraints floatPercent = {0.0,100.0,1.0};
 
43
 
 
44
 
 
45
FeatureTest::FeatureTest()
 
46
{
 
47
  ADD_PROPERTY(Integer,(4711)  );
 
48
  ADD_PROPERTY(Float  ,(47.11f) );
 
49
  ADD_PROPERTY(Bool   ,(true)  );
 
50
  ADD_PROPERTY(String ,("4711"));
 
51
  ADD_PROPERTY(Path   ,("c:\\temp"));
 
52
  ADD_PROPERTY(StringList ,("4711"));
 
53
 
 
54
  ADD_PROPERTY(Enum   ,(4));
 
55
  Enum.setEnums(enums);
 
56
  ADD_PROPERTY(ConstraintInt ,(5));
 
57
  ConstraintInt.setConstraints(&intPercent);
 
58
  ADD_PROPERTY(ConstraintFloat ,(5.0));
 
59
  ConstraintFloat.setConstraints(&floatPercent);
 
60
 
 
61
  App::Color c;
 
62
  ADD_PROPERTY(Colour      ,(c) );
 
63
  ADD_PROPERTY(ColourList  ,(c) );
 
64
 
 
65
  ADD_PROPERTY(Distance,(47.11f) );
 
66
  ADD_PROPERTY(Angle   ,(3.0f) );
 
67
 
 
68
  ADD_PROPERTY(IntegerList,(4711)  );
 
69
  ADD_PROPERTY(FloatList  ,(47.11f) );
 
70
  
 
71
  ADD_PROPERTY(Link     ,(0));
 
72
  ADD_PROPERTY(LinkList ,(0));
 
73
 
 
74
  ADD_PROPERTY(Vector    ,(1.0,2.0,3.0));
 
75
  ADD_PROPERTY(VectorList,(3.0,2.0,1.0));
 
76
  ADD_PROPERTY(Matrix    ,(Base::Matrix4D(1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0)));
 
77
  ADD_PROPERTY(Placement ,(Base::Placement()));
 
78
  
 
79
  // properties for recompute testing
 
80
  static const char* group = "Feature Test";
 
81
  ADD_PROPERTY_TYPE(Source1       ,(0),group,Prop_None,"Source for testing links");
 
82
  ADD_PROPERTY_TYPE(Source2       ,(0),group,Prop_None,"Source for testing links");
 
83
  ADD_PROPERTY_TYPE(SourceN       ,(0),group,Prop_None,"Source for testing links");
 
84
  ADD_PROPERTY_TYPE(ExecResult    ,("empty"),group,Prop_None,"Result of the execution");
 
85
  ADD_PROPERTY_TYPE(ExceptionType ,(0),group,Prop_None,"The type of exception the execution method throws");
 
86
  ADD_PROPERTY_TYPE(ExecCount     ,(0),group,Prop_None,"Number of executions");
 
87
  
 
88
  // properties with types
 
89
  ADD_PROPERTY_TYPE(TypeHidden  ,(4711),group,Prop_Hidden,"An example property which has the type 'Hidden'"  );
 
90
  ADD_PROPERTY_TYPE(TypeReadOnly,(4711),group,Prop_ReadOnly ,"An example property which has the type 'ReadOnly'"  );
 
91
  ADD_PROPERTY_TYPE(TypeOutput  ,(4711),group,Prop_Output ,"An example property which has the type 'Transient'"  );
 
92
  ADD_PROPERTY_TYPE(TypeTransient,(4711),group,Prop_Transient ,"An example property which has the type 'Transient'"  );
 
93
  ADD_PROPERTY_TYPE(TypeAll     ,(4711),group,(App::PropertyType) (Prop_Output|Prop_ReadOnly |Prop_Hidden ),
 
94
      "An example property which has the types 'Output', 'ReadOnly' and 'Hidden'");
 
95
 
 
96
}
 
97
 
 
98
 
 
99
DocumentObjectExecReturn *FeatureTest::execute(void)
 
100
{
 
101
 
 
102
 
 
103
  switch(ExceptionType.getValue()) 
 
104
  {
 
105
    case 0: break;
 
106
    case 1: throw "Test Exeption";
 
107
    case 2: throw Base::Exception("FeatureTestException::execute(): Testexception");
 
108
  }
 
109
  ExecCount.setValue(ExecCount.getValue() + 1);
 
110
 
 
111
  ExecResult.setValue("Exec");
 
112
 
 
113
  return DocumentObject::StdReturn;
 
114
}
 
115
 
 
116
 
 
117
PROPERTY_SOURCE(App::FeatureTestException, App::FeatureTest)
 
118
 
 
119
 
 
120
FeatureTestException::FeatureTestException()
 
121
{
 
122
  ADD_PROPERTY(ExceptionType,(Base::Exception::getClassTypeId().getKey())  );
 
123
}
 
124
 
 
125
DocumentObjectExecReturn *FeatureTestException::execute(void)
 
126
{
 
127
  //ExceptionType;
 
128
 
 
129
  throw Base::Exception("FeatureTestException::execute(): Testexception  ;-)");
 
130
 
 
131
  return 0;
 
132
}