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 <QAction>
00028 # include <QMenu>
00029 # include <Standard_math.hxx>
00030 # include <Inventor/actions/SoSearchAction.h>
00031 # include <Inventor/draggers/SoDragger.h>
00032 # include <Inventor/nodes/SoCoordinate3.h>
00033 # include <Inventor/nodes/SoFaceSet.h>
00034 # include <Inventor/nodes/SoMaterial.h>
00035 # include <Inventor/nodes/SoSeparator.h>
00036 # include <Inventor/manips/SoCenterballManip.h>
00037 #endif
00038
00039 #include <Mod/Part/App/FeatureMirroring.h>
00040 #include <Mod/Part/App/FeatureFillet.h>
00041 #include <Gui/Application.h>
00042 #include <Gui/Control.h>
00043 #include <Gui/Document.h>
00044 #include "ViewProviderMirror.h"
00045 #include "DlgFilletEdges.h"
00046
00047 using namespace PartGui;
00048
00049
00050 PROPERTY_SOURCE(PartGui::ViewProviderMirror, PartGui::ViewProviderPart)
00051
00052 ViewProviderMirror::ViewProviderMirror()
00053 {
00054 sPixmap = "Part_MirrorPNG";
00055 pcEditNode = new SoSeparator();
00056 pcEditNode->ref();
00057 }
00058
00059 ViewProviderMirror::~ViewProviderMirror()
00060 {
00061 pcEditNode->unref();
00062 }
00063
00064 void ViewProviderMirror::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
00065 {
00066 QAction* act;
00067 act = menu->addAction(QObject::tr("Edit mirror plane"), receiver, member);
00068 act->setData(QVariant((int)ViewProvider::Default));
00069 ViewProviderPart::setupContextMenu(menu, receiver, member);
00070 }
00071
00072 bool ViewProviderMirror::setEdit(int ModNum)
00073 {
00074 if (ModNum == ViewProvider::Default) {
00075
00076 Part::Mirroring* mf = static_cast<Part::Mirroring*>(getObject());
00077 Base::BoundBox3d bbox = mf->Shape.getBoundingBox();
00078 float len = (float)bbox.CalcDiagonalLength();
00079 Base::Vector3f base = mf->Base.getValue();
00080 Base::Vector3f norm = mf->Normal.getValue();
00081 Base::Vector3d cent = bbox.CalcCenter();
00082 Base::Vector3f cbox((float)cent.x,(float)cent.y,(float)cent.z);
00083 base = cbox.ProjToPlane(base, norm);
00084
00085
00086 SoTransform* trans = new SoTransform;
00087 SbRotation rot(SbVec3f(0,0,1), SbVec3f(norm.x,norm.y,norm.z));
00088 trans->rotation.setValue(rot);
00089 trans->translation.setValue(base.x,base.y,base.z);
00090 trans->center.setValue(0.0f,0.0f,0.0f);
00091
00092 SoMaterial* color = new SoMaterial();
00093 color->diffuseColor.setValue(0,0,1);
00094 color->transparency.setValue(0.5);
00095 SoCoordinate3* points = new SoCoordinate3();
00096 points->point.setNum(4);
00097 points->point.set1Value(0, -len/2,-len/2,0);
00098 points->point.set1Value(1, len/2,-len/2,0);
00099 points->point.set1Value(2, len/2, len/2,0);
00100 points->point.set1Value(3, -len/2, len/2,0);
00101 SoFaceSet* face = new SoFaceSet();
00102 pcEditNode->addChild(trans);
00103 pcEditNode->addChild(color);
00104 pcEditNode->addChild(points);
00105 pcEditNode->addChild(face);
00106
00107
00108
00109
00110
00111 SoSearchAction sa;
00112 sa.setInterest(SoSearchAction::FIRST);
00113 sa.setSearchingAll(FALSE);
00114 sa.setNode(trans);
00115 sa.apply(pcEditNode);
00116 SoPath * path = sa.getPath();
00117 if (path) {
00118 SoCenterballManip * manip = new SoCenterballManip;
00119 manip->replaceNode(path);
00120
00121 SoDragger* dragger = manip->getDragger();
00122 dragger->addStartCallback(dragStartCallback, this);
00123 dragger->addFinishCallback(dragFinishCallback, this);
00124 dragger->addMotionCallback(dragMotionCallback, this);
00125 }
00126 pcRoot->addChild(pcEditNode);
00127 }
00128 else {
00129 ViewProviderPart::setEdit(ModNum);
00130 }
00131
00132 return true;
00133 }
00134
00135 void ViewProviderMirror::unsetEdit(int ModNum)
00136 {
00137 if (ModNum == ViewProvider::Default) {
00138 SoCenterballManip* manip = static_cast<SoCenterballManip *>(pcEditNode->getChild(0));
00139
00140 SbVec3f move = manip->translation.getValue();
00141 SbVec3f center = manip->center.getValue();
00142 SbRotation rot = manip->rotation.getValue();
00143
00144
00145 move += center;
00146 rot.multVec(center,center);
00147 move -= center;
00148
00149
00150 SbVec3f norm(0,0,1);
00151 rot.multVec(norm,norm);
00152
00153
00154 Part::Mirroring* mf = static_cast<Part::Mirroring*>(getObject());
00155 mf->Base.setValue(move[0],move[1],move[2]);
00156 mf->Normal.setValue(norm[0],norm[1],norm[2]);
00157
00158 pcRoot->removeChild(pcEditNode);
00159 pcEditNode->removeAllChildren();
00160 }
00161 else {
00162 ViewProviderPart::unsetEdit(ModNum);
00163 }
00164 }
00165
00166 void ViewProviderMirror::dragStartCallback(void *data, SoDragger *)
00167 {
00168
00169 Gui::Application::Instance->activeDocument()->openCommand("Edit Mirror");
00170 }
00171
00172 void ViewProviderMirror::dragFinishCallback(void *data, SoDragger *)
00173 {
00174
00175 Gui::Application::Instance->activeDocument()->commitCommand();
00176 }
00177
00178 void ViewProviderMirror::dragMotionCallback(void *data, SoDragger *drag)
00179 {
00180 ViewProviderMirror* that = reinterpret_cast<ViewProviderMirror*>(data);
00181 const SbMatrix& mat = drag->getMotionMatrix();
00182
00183 SbRotation rot(mat);
00184 SbVec3f norm(0,0,1);
00185 rot.multVec(norm,norm);
00186 Part::Mirroring* mf = static_cast<Part::Mirroring*>(that->getObject());
00187 mf->Base.setValue(mat[3][0],mat[3][1],mat[3][2]);
00188 mf->Normal.setValue(norm[0],norm[1],norm[2]);
00189 }
00190
00191
00192
00193 PROPERTY_SOURCE(PartGui::ViewProviderFillet, PartGui::ViewProviderPart)
00194
00195 ViewProviderFillet::ViewProviderFillet()
00196 {
00197 sPixmap = "Part_Fillet";
00198 }
00199
00200 ViewProviderFillet::~ViewProviderFillet()
00201 {
00202 }
00203
00204 void ViewProviderFillet::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
00205 {
00206 QAction* act;
00207 act = menu->addAction(QObject::tr("Edit fillet edges"), receiver, member);
00208 act->setData(QVariant((int)ViewProvider::Default));
00209 PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member);
00210 }
00211
00212 bool ViewProviderFillet::setEdit(int ModNum)
00213 {
00214 if (ModNum == ViewProvider::Default ) {
00215 if (Gui::Control().activeDialog())
00216 return false;
00217 Part::Fillet* fillet = static_cast<Part::Fillet*>(getObject());
00218 Gui::Control().showDialog(new PartGui::TaskFilletEdges(fillet));
00219 return true;
00220 }
00221 else {
00222 ViewProviderPart::setEdit(ModNum);
00223 return true;
00224 }
00225 }
00226
00227 void ViewProviderFillet::unsetEdit(int ModNum)
00228 {
00229 if (ModNum == ViewProvider::Default) {
00230 Gui::Control().closeDialog();
00231 }
00232 else {
00233 ViewProviderPart::unsetEdit(ModNum);
00234 }
00235 }
00236
00237 std::vector<App::DocumentObject*> ViewProviderFillet::claimChildren() const
00238 {
00239 std::vector<App::DocumentObject*> temp;
00240 temp.push_back(static_cast<Part::Fillet*>(getObject())->Base.getValue());
00241 return temp;
00242 }
00243
00244
00245
00246 PROPERTY_SOURCE(PartGui::ViewProviderChamfer, PartGui::ViewProviderPart)
00247
00248 ViewProviderChamfer::ViewProviderChamfer()
00249 {
00250 sPixmap = "Part_Chamfer";
00251 }
00252
00253 ViewProviderChamfer::~ViewProviderChamfer()
00254 {
00255 }