ViewProviderTransformDemolding.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025
00026 #ifndef _PreComp_
00027 # include <Inventor/nodes/SoDrawStyle.h>
00028 # include <Inventor/nodes/SoIndexedFaceSet.h>
00029 # include <Inventor/nodes/SoMaterial.h>
00030 # include <Inventor/nodes/SoMaterialBinding.h>
00031 # include <Inventor/draggers/SoTrackballDragger.h>
00032 # include <Inventor/nodes/SoAntiSquish.h>
00033 # include <Inventor/nodes/SoSurroundScale.h>
00034 # include <Inventor/nodes/SoSeparator.h>
00035 # include <Inventor/manips/SoTransformerManip.h>
00036 #endif
00037
00038 #include "ViewProviderTransformDemolding.h"
00039
00041 #include <Base/Console.h>
00042 #include <Base/Parameter.h>
00043 #include <Base/Exception.h>
00044 #include <App/Application.h>
00045 #include <Gui/Selection.h>
00046 #include <Gui/SoFCSelection.h>
00047 #include <Base/Sequencer.h>
00048
00049
00050 #include <Mod/Mesh/App/MeshFeature.h>
00051 #include <Mod/Mesh/App/Mesh.h>
00052 #include <Mod/Mesh/App/Core/Iterator.h>
00053
00054 using Mesh::Feature;
00055 using MeshCore::MeshKernel;
00056 using MeshCore::MeshFacetIterator;
00057 using MeshCore::MeshGeomFacet;
00058 using namespace MeshGui;
00059
00060
00061 PROPERTY_SOURCE(MeshGui::ViewProviderMeshTransformDemolding, MeshGui::ViewProviderMesh)
00062
00063
00064 ViewProviderMeshTransformDemolding::ViewProviderMeshTransformDemolding()
00065 {
00066 pcTrackballDragger = new SoTrackballDragger;
00067 pcTrackballDragger->ref();
00068 }
00069
00070 ViewProviderMeshTransformDemolding::~ViewProviderMeshTransformDemolding()
00071 {
00072 pcTrackballDragger->unref();
00073 }
00074
00075 void ViewProviderMeshTransformDemolding::attach(App::DocumentObject *pcFeat)
00076 {
00077
00078 ViewProviderMesh::attach(pcFeat);
00079
00080 SoGroup* pcDemoldRoot = new SoGroup();
00081
00082 SoDrawStyle *pcFlatStyle = new SoDrawStyle();
00083 pcFlatStyle->style = SoDrawStyle::FILLED;
00084 pcDemoldRoot->addChild(pcFlatStyle);
00085
00086
00087 SoSeparator * surroundsep = new SoSeparator;
00088
00089 SoSurroundScale * ss = new SoSurroundScale;
00090 ss->numNodesUpToReset = 1;
00091 ss->numNodesUpToContainer = 2;
00092 surroundsep->addChild(ss);
00093
00094 SoAntiSquish * antisquish = new SoAntiSquish;
00095 antisquish->sizing = SoAntiSquish::AVERAGE_DIMENSION ;
00096 surroundsep->addChild(antisquish);
00097
00098 pcTrackballDragger->addValueChangedCallback(sValueChangedCallback,this);
00099 pcTrackballDragger->addFinishCallback (sDragEndCallback,this);
00100 surroundsep->addChild(pcTrackballDragger);
00101
00102 pcTransformDrag = new SoTransform();
00103
00104
00105 SoMaterialBinding* pcMatBinding = new SoMaterialBinding;
00106
00107 pcMatBinding->value = SoMaterialBinding::PER_FACE_INDEXED;
00108 pcColorMat = new SoMaterial;
00109 pcColorMat->diffuseColor.set1Value(0, 1,1,0);
00110 pcColorMat->diffuseColor.set1Value(1, 1,0,0);
00111 pcColorMat->diffuseColor.set1Value(2, 0,1,0);
00112
00113 pcDemoldRoot->addChild(surroundsep);
00114 pcDemoldRoot->addChild(pcTransformDrag);
00115 pcDemoldRoot->addChild(pcColorMat);
00116 pcDemoldRoot->addChild(pcMatBinding);
00117 pcDemoldRoot->addChild(pcHighlight);
00118
00119
00120 addDisplayMaskMode(pcDemoldRoot, "Demold");
00121
00122 calcNormalVector();
00123 calcMaterialIndex(SbRotation());
00124
00125 center = dynamic_cast<Feature*>(pcObject)->Mesh.getValue().getKernel().GetBoundBox().CalcCenter();
00126
00127
00128
00129
00130 }
00131
00132 void ViewProviderMeshTransformDemolding::calcNormalVector(void)
00133 {
00134 const MeshKernel& cMesh = dynamic_cast<Feature*>(pcObject)->Mesh.getValue().getKernel();
00135
00136 MeshFacetIterator cFIt(cMesh);
00137 for( cFIt.Init(); cFIt.More(); cFIt.Next())
00138 {
00139 const MeshGeomFacet& rFace = *cFIt;
00140
00141 Base::Vector3f norm(rFace.GetNormal());
00142 normalVector.push_back(SbVec3f(norm.x,norm.y,norm.z));
00143 }
00144 }
00145
00146 void ViewProviderMeshTransformDemolding::calcMaterialIndex(const SbRotation &rot)
00147 {
00148
00149 SbVec3f Up(0,0,1),result;
00150
00151 unsigned long i=0;
00152 for( std::vector<SbVec3f>::const_iterator it=normalVector.begin();it != normalVector.end(); ++it,i++)
00153 {
00154 rot.multVec(*it,result);
00155
00156 float Angle = acos( (result.dot(Up)) / (result.length() * Up.length()) ) * (180/3.1415926535);
00157
00158 if(Angle < 87.0){
00159
00160 }else if(Angle > 90.0){
00161
00162 }else{
00163
00164 }
00165
00166 }
00167 }
00168
00169 void ViewProviderMeshTransformDemolding::sValueChangedCallback(void *This, SoDragger *)
00170 {
00171 static_cast<ViewProviderMeshTransformDemolding*>(This)->valueChangedCallback();
00172 }
00173
00174 void ViewProviderMeshTransformDemolding::sDragEndCallback(void *This, SoDragger *)
00175 {
00176 static_cast<ViewProviderMeshTransformDemolding*>(This)->DragEndCallback();
00177 }
00178
00179 void ViewProviderMeshTransformDemolding::DragEndCallback(void)
00180 {
00181 SbRotation rot = pcTrackballDragger->rotation.getValue();
00182 calcMaterialIndex(rot);
00183
00184 Base::Console().Log("View: Finish draging\n");
00185
00186 }
00187
00188 void ViewProviderMeshTransformDemolding::valueChangedCallback(void)
00189 {
00190
00191
00192
00193 SbMatrix temp;
00194 SbRotation rot = pcTrackballDragger->rotation.getValue();
00195
00196
00197
00198 temp.setTransform( SbVec3f(0,0,0),
00199 rot,
00200 SbVec3f(1,1,1),
00201 SbRotation() ,
00202 SbVec3f(center.x,center.y,center.z));
00203 pcTransformDrag->setMatrix( temp );
00204 }
00205
00206 void ViewProviderMeshTransformDemolding::setDisplayMode(const char* ModeName)
00207 {
00208 if ( strcmp("Demold",ModeName) == 0 )
00209 setDisplayMaskMode("Demold");
00210 ViewProviderMesh::setDisplayMode(ModeName);
00211 }
00212
00213 const char* ViewProviderMeshTransformDemolding::getDefaultDisplayMode() const
00214 {
00215 return "Demold";
00216 }
00217
00218 std::vector<std::string> ViewProviderMeshTransformDemolding::getDisplayModes(void) const
00219 {
00220 std::vector<std::string> StrList = ViewProviderMesh::getDisplayModes();
00221 StrList.push_back("Demold");
00222 return StrList;
00223 }