FeatureTest.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) Jürgen Riegel          (juergen.riegel@web.de) 2002     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023  
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 #endif
00027 
00028 
00029 #include <Base/Console.h>
00030 #include <Base/Exception.h>
00031 #include "FeatureTest.h"
00032 #include "Material.h"
00033 
00034 #define new DEBUG_CLIENTBLOCK
00035 using namespace App;
00036 
00037 
00038 PROPERTY_SOURCE(App::FeatureTest, App::DocumentObject)
00039 
00040 const char* enums[]= {"Zero","One","Two","Three","Four",NULL};
00041 const PropertyIntegerConstraint::Constraints intPercent = {0,100,1};
00042 const PropertyFloatConstraint::Constraints floatPercent = {0.0,100.0,1.0};
00043 
00044 
00045 FeatureTest::FeatureTest()
00046 {
00047   ADD_PROPERTY(Integer,(4711)  );
00048   ADD_PROPERTY(Float  ,(47.11f) );
00049   ADD_PROPERTY(Bool   ,(true)  );
00050   ADD_PROPERTY(String ,("4711"));
00051   ADD_PROPERTY(Path   ,("c:\\temp"));
00052   ADD_PROPERTY(StringList ,("4711"));
00053 
00054   ADD_PROPERTY(Enum   ,(4));
00055   Enum.setEnums(enums);
00056   ADD_PROPERTY(ConstraintInt ,(5));
00057   ConstraintInt.setConstraints(&intPercent);
00058   ADD_PROPERTY(ConstraintFloat ,(5.0));
00059   ConstraintFloat.setConstraints(&floatPercent);
00060 
00061   App::Color c;
00062   ADD_PROPERTY(Colour      ,(c) );
00063   ADD_PROPERTY(ColourList  ,(c) );
00064 
00065   ADD_PROPERTY(Distance,(47.11f) );
00066   ADD_PROPERTY(Angle   ,(3.0f) );
00067 
00068   ADD_PROPERTY(IntegerList,(4711)  );
00069   ADD_PROPERTY(FloatList  ,(47.11f) );
00070   
00071   ADD_PROPERTY(Link     ,(0));
00072   ADD_PROPERTY(LinkSub,  (0));
00073   ADD_PROPERTY(LinkList ,(0));
00074 
00075   ADD_PROPERTY(Vector    ,(1.0,2.0,3.0));
00076   ADD_PROPERTY(VectorList,(3.0,2.0,1.0));
00077   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)));
00078   ADD_PROPERTY(Placement ,(Base::Placement()));
00079   
00080   // properties for recompute testing
00081   static const char* group = "Feature Test";
00082   ADD_PROPERTY_TYPE(Source1       ,(0),group,Prop_None,"Source for testing links");
00083   ADD_PROPERTY_TYPE(Source2       ,(0),group,Prop_None,"Source for testing links");
00084   ADD_PROPERTY_TYPE(SourceN       ,(0),group,Prop_None,"Source for testing links");
00085   ADD_PROPERTY_TYPE(ExecResult    ,("empty"),group,Prop_None,"Result of the execution");
00086   ADD_PROPERTY_TYPE(ExceptionType ,(0),group,Prop_None,"The type of exception the execution method throws");
00087   ADD_PROPERTY_TYPE(ExecCount     ,(0),group,Prop_None,"Number of executions");
00088   
00089   // properties with types
00090   ADD_PROPERTY_TYPE(TypeHidden  ,(4711),group,Prop_Hidden,"An example property which has the type 'Hidden'"  );
00091   ADD_PROPERTY_TYPE(TypeReadOnly,(4711),group,Prop_ReadOnly ,"An example property which has the type 'ReadOnly'"  );
00092   ADD_PROPERTY_TYPE(TypeOutput  ,(4711),group,Prop_Output ,"An example property which has the type 'Output'"  );
00093   ADD_PROPERTY_TYPE(TypeTransient,(4711),group,Prop_Transient ,"An example property which has the type 'Transient'"  );
00094   ADD_PROPERTY_TYPE(TypeAll     ,(4711),group,(App::PropertyType) (Prop_Output|Prop_ReadOnly |Prop_Hidden ),
00095       "An example property which has the types 'Output', 'ReadOnly' and 'Hidden'");
00096  
00097 }
00098 
00099 FeatureTest::~FeatureTest()
00100 {
00101 
00102 }
00103 DocumentObjectExecReturn *FeatureTest::execute(void)
00104 {
00105 
00106 
00107   switch(ExceptionType.getValue()) 
00108   {
00109     case 0: break;
00110     case 1: throw "Test Exeption";
00111     case 2: throw Base::Exception("FeatureTestException::execute(): Testexception");
00112   }
00113   ExecCount.setValue(ExecCount.getValue() + 1);
00114 
00115   ExecResult.setValue("Exec");
00116 
00117   return DocumentObject::StdReturn;
00118 }
00119 
00120 
00121 PROPERTY_SOURCE(App::FeatureTestException, App::FeatureTest)
00122 
00123 
00124 FeatureTestException::FeatureTestException()
00125 {
00126   ADD_PROPERTY(ExceptionType,(Base::Exception::getClassTypeId().getKey())  );
00127 }
00128 
00129 DocumentObjectExecReturn *FeatureTestException::execute(void)
00130 {
00131   //ExceptionType;
00132 
00133   throw Base::Exception("FeatureTestException::execute(): Testexception  ;-)");
00134 
00135   return 0;
00136 }

Generated on Wed Nov 23 19:00:13 2011 for FreeCAD by  doxygen 1.6.1