ViewProviderReference.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2004 Jrgen Riegel <juergen.riegel@web.de>               *
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 
00026 #ifndef _PreComp_
00027 # include <Poly_Polygon3D.hxx>
00028 # include <BRepBndLib.hxx>
00029 # include <BRepMesh.hxx>
00030 # include <BRepMesh_IncrementalMesh.hxx>
00031 # include <BRep_Tool.hxx>
00032 # include <BRepTools.hxx>
00033 # include <BRepAdaptor_Curve.hxx>
00034 # include <BRepAdaptor_Surface.hxx>
00035 # include <GeomAbs_CurveType.hxx>
00036 # include <GeomAbs_SurfaceType.hxx>
00037 # include <Geom_BezierCurve.hxx>
00038 # include <Geom_BSplineCurve.hxx>
00039 # include <Geom_BezierSurface.hxx>
00040 # include <Geom_BSplineSurface.hxx>
00041 # include <GeomAPI_ProjectPointOnSurf.hxx>
00042 # include <GeomLProp_SLProps.hxx>
00043 # include <gp_Trsf.hxx>
00044 # include <Poly_Array1OfTriangle.hxx>
00045 # include <Poly_Triangulation.hxx>
00046 # include <TColgp_Array1OfPnt.hxx>
00047 # include <TopoDS.hxx>
00048 # include <TopoDS_Edge.hxx>
00049 # include <TopoDS_Wire.hxx>
00050 # include <TopoDS_Face.hxx>
00051 # include <TopoDS_Shape.hxx>
00052 # include <TopoDS_Iterator.hxx>
00053 # include <TopExp_Explorer.hxx>
00054 # include <TopExp.hxx>
00055 # include <TopTools_IndexedMapOfShape.hxx>
00056 # include <Poly_PolygonOnTriangulation.hxx>
00057 # include <TColStd_Array1OfInteger.hxx>
00058 # include <TopTools_ListOfShape.hxx>
00059 # include <Inventor/SoPickedPoint.h>
00060 # include <Inventor/events/SoMouseButtonEvent.h>
00061 # include <Inventor/nodes/SoCoordinate3.h>
00062 # include <Inventor/nodes/SoDrawStyle.h>
00063 # include <Inventor/nodes/SoIndexedFaceSet.h>
00064 # include <Inventor/nodes/SoLineSet.h>
00065 # include <Inventor/nodes/SoLocateHighlight.h>
00066 # include <Inventor/nodes/SoMaterial.h>
00067 # include <Inventor/nodes/SoNormal.h>
00068 # include <Inventor/nodes/SoNormalBinding.h>
00069 # include <Inventor/nodes/SoPointSet.h>
00070 # include <Inventor/nodes/SoShapeHints.h>
00071 # include <Inventor/nodes/SoSwitch.h>
00072 # include <Inventor/nodes/SoGroup.h>
00073 # include <Inventor/nodes/SoSphere.h>
00074 # include <Inventor/nodes/SoScale.h>
00075 #endif
00076 
00078 #include <Base/Console.h>
00079 #include <Base/Parameter.h>
00080 #include <Base/Exception.h>
00081 #include <App/Application.h>
00082 #include <App/Document.h>
00083 #include <Gui/SoFCSelection.h>
00084 #include <Gui/Selection.h>
00085 #include <Gui/View3DInventorViewer.h>
00086 
00087 
00088 #include "ViewProvider.h"
00089 #include "ViewProviderReference.h"
00090 #include "SoFCShapeObject.h"
00091 
00092 #include <Mod/Part/App/PartFeature.h>
00093 #include <Mod/Part/App/PrimitiveFeature.h>
00094 
00095 
00096 using namespace PartGui;
00097 
00098 PROPERTY_SOURCE(PartGui::ViewProviderPartReference, Gui::ViewProviderGeometryObject)
00099 
00100 //**************************************************************************
00101 // Construction/Destruction
00102 
00103 ViewProviderPartReference::ViewProviderPartReference() : pcControlPoints(0)
00104 {
00105     App::Material mat;
00106     mat.ambientColor.set(0.2f,0.2f,0.2f);
00107     mat.diffuseColor.set(0.1f,0.1f,0.1f);
00108     mat.specularColor.set(0.0f,0.0f,0.0f);
00109     mat.emissiveColor.set(0.0f,0.0f,0.0f);
00110     mat.shininess = 0.0f;
00111     mat.transparency = 0.0f;
00112     //ADD_PROPERTY(LineMaterial,(mat));
00113     //ADD_PROPERTY(PointMaterial,(mat));
00114     //ADD_PROPERTY(LineColor,(mat.diffuseColor));
00115     //ADD_PROPERTY(PointColor,(mat.diffuseColor));
00116     //ADD_PROPERTY(LineWidth,(2.0f));
00117     //LineWidth.setConstraints(&floatRange);
00118     //PointSize.setConstraints(&floatRange);
00119     //ADD_PROPERTY(PointSize,(2.0f));
00120     //ADD_PROPERTY(ControlPoints,(false));
00121     //ADD_PROPERTY(Lighting,(1));
00122     //Lighting.setEnums(LightingEnums);
00123 
00124     //EdgeRoot = new SoSeparator();
00125     //EdgeRoot->ref();
00126     //FaceRoot = new SoSeparator();
00127     //FaceRoot->ref();
00128     //VertexRoot = new SoSeparator();
00129     //VertexRoot->ref();
00130     //pcLineMaterial = new SoMaterial;
00131     //pcLineMaterial->ref();
00132     //LineMaterial.touch();
00133 
00134     //pcPointMaterial = new SoMaterial;
00135     //pcPointMaterial->ref();
00136     //PointMaterial.touch();
00137 
00138     //pcLineStyle = new SoDrawStyle();
00139     //pcLineStyle->ref();
00140     //pcLineStyle->style = SoDrawStyle::LINES;
00141     //pcLineStyle->lineWidth = LineWidth.getValue();
00142 
00143     //pcPointStyle = new SoDrawStyle();
00144     //pcPointStyle->ref();
00145     //pcPointStyle->style = SoDrawStyle::POINTS;
00146     //pcPointStyle->pointSize = PointSize.getValue();
00147 
00148     //pShapeHints = new SoShapeHints;
00149     //pShapeHints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE;
00150     //pShapeHints->ref();
00151     //Lighting.touch();
00152 
00153     sPixmap = "Tree_Part";
00154     //loadParameter();
00155 }
00156 
00157 ViewProviderPartReference::~ViewProviderPartReference()
00158 {
00159     //EdgeRoot->unref();
00160     //FaceRoot->unref();
00161     //VertexRoot->unref();
00162     //pcLineMaterial->unref();
00163     //pcPointMaterial->unref();
00164     //pcLineStyle->unref();
00165     //pcPointStyle->unref();
00166     //pShapeHints->unref();
00167 }
00168 
00169 void ViewProviderPartReference::onChanged(const App::Property* prop)
00170 {
00171     //if (prop == &LineWidth) {
00172     //    pcLineStyle->lineWidth = LineWidth.getValue();
00173     //}
00174     //else if (prop == &PointSize) {
00175     //    pcPointStyle->pointSize = PointSize.getValue();
00176     //}
00177     //else if (prop == &LineColor) {
00178     //    const App::Color& c = LineColor.getValue();
00179     //    pcLineMaterial->diffuseColor.setValue(c.r,c.g,c.b);
00180     //    if (c != LineMaterial.getValue().diffuseColor)
00181     //    LineMaterial.setDiffuseColor(c);
00182     //}
00183     //else if (prop == &PointColor) {
00184     //    const App::Color& c = PointColor.getValue();
00185     //    pcPointMaterial->diffuseColor.setValue(c.r,c.g,c.b);
00186     //    if (c != PointMaterial.getValue().diffuseColor)
00187     //    PointMaterial.setDiffuseColor(c);
00188     //}
00189     //else if (prop == &LineMaterial) {
00190     //    const App::Material& Mat = LineMaterial.getValue();
00191     //    if (LineColor.getValue() != Mat.diffuseColor)
00192     //    LineColor.setValue(Mat.diffuseColor);
00193     //    pcLineMaterial->ambientColor.setValue(Mat.ambientColor.r,Mat.ambientColor.g,Mat.ambientColor.b);
00194     //    pcLineMaterial->diffuseColor.setValue(Mat.diffuseColor.r,Mat.diffuseColor.g,Mat.diffuseColor.b);
00195     //    pcLineMaterial->specularColor.setValue(Mat.specularColor.r,Mat.specularColor.g,Mat.specularColor.b);
00196     //    pcLineMaterial->emissiveColor.setValue(Mat.emissiveColor.r,Mat.emissiveColor.g,Mat.emissiveColor.b);
00197     //    pcLineMaterial->shininess.setValue(Mat.shininess);
00198     //    pcLineMaterial->transparency.setValue(Mat.transparency);
00199     //}
00200     //else if (prop == &PointMaterial) {
00201     //    const App::Material& Mat = PointMaterial.getValue();
00202     //    if (PointColor.getValue() != Mat.diffuseColor)
00203     //    PointColor.setValue(Mat.diffuseColor);
00204     //    pcPointMaterial->ambientColor.setValue(Mat.ambientColor.r,Mat.ambientColor.g,Mat.ambientColor.b);
00205     //    pcPointMaterial->diffuseColor.setValue(Mat.diffuseColor.r,Mat.diffuseColor.g,Mat.diffuseColor.b);
00206     //    pcPointMaterial->specularColor.setValue(Mat.specularColor.r,Mat.specularColor.g,Mat.specularColor.b);
00207     //    pcPointMaterial->emissiveColor.setValue(Mat.emissiveColor.r,Mat.emissiveColor.g,Mat.emissiveColor.b);
00208     //    pcPointMaterial->shininess.setValue(Mat.shininess);
00209     //    pcPointMaterial->transparency.setValue(Mat.transparency);
00210     //}
00211     //else if (prop == &ControlPoints) {
00212     //    App::DocumentObject* obj = this->pcObject;
00213     //    App::Property* shape = obj->getPropertyByName("Shape");
00214     //    showControlPoints(ControlPoints.getValue(), shape);
00215     //}
00216     //else if (prop == &Lighting) {
00217     //    if (Lighting.getValue() == 0)
00218     //        pShapeHints->vertexOrdering = SoShapeHints::UNKNOWN_ORDERING;
00219     //    else
00220     //        pShapeHints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE;
00221     //}
00222     //else {
00223     //    ViewProviderGeometryObject::onChanged(prop);
00224     //}
00225 }
00226 
00227 void ViewProviderPartReference::attach(App::DocumentObject *pcFeat)
00228 {
00229     // call parent attach method
00230     ViewProviderGeometryObject::attach(pcFeat);
00231 
00232     SoGroup* pcNormalRoot = new SoGroup();
00233     SoGroup* pcFlatRoot = new SoGroup();
00234     SoGroup* pcWireframeRoot = new SoGroup();
00235     SoGroup* pcPointsRoot = new SoGroup();
00236 
00237     // enable two-side rendering
00238     pShapeHints->vertexOrdering = SoShapeHints::COUNTERCLOCKWISE;
00239     pShapeHints->shapeType = SoShapeHints::UNKNOWN_SHAPE_TYPE;
00240 
00241     // normal viewing with edges and points
00242     pcNormalRoot->addChild(pShapeHints);
00243     pcNormalRoot->addChild(FaceRoot);
00244     pcNormalRoot->addChild(EdgeRoot);
00245     pcNormalRoot->addChild(VertexRoot);
00246 
00247     // just faces with no edges or points
00248     pcFlatRoot->addChild(pShapeHints);
00249     pcFlatRoot->addChild(FaceRoot);
00250 
00251     // only edges
00252     pcWireframeRoot->addChild(EdgeRoot);
00253     pcWireframeRoot->addChild(VertexRoot);
00254 
00255     // normal viewing with edges and points
00256     pcPointsRoot->addChild(VertexRoot);
00257 
00258     // putting all together with the switch
00259     addDisplayMaskMode(pcNormalRoot, "Reference");
00260 }
00261 
00262 void ViewProviderPartReference::setDisplayMode(const char* ModeName)
00263 {
00264     if ( strcmp("Reference",ModeName)==0 )
00265         setDisplayMaskMode("Reference");
00266         
00267     ViewProviderGeometryObject::setDisplayMode( ModeName );
00268 }
00269 
00270 std::vector<std::string> ViewProviderPartReference::getDisplayModes(void) const
00271 {
00272     // get the modes of the father
00273     std::vector<std::string> StrList = ViewProviderGeometryObject::getDisplayModes();
00274 
00275     // add your own modes
00276     StrList.push_back("Flat Lines");
00277     StrList.push_back("Shaded");
00278     StrList.push_back("Wireframe");
00279     StrList.push_back("Points");
00280 
00281     return StrList;
00282 }
00283 
00284 
00285 void ViewProviderPartReference::updateData(const App::Property* prop)
00286 {
00287 }

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