FeatureViewPart.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 <sstream>
00028 #endif
00029
00030
00031 #include <HLRBRep_Algo.hxx>
00032 #include <TopoDS_Shape.hxx>
00033 #include <HLRTopoBRep_OutLiner.hxx>
00034
00035 #include <HLRAlgo_Projector.hxx>
00036 #include <HLRBRep_ShapeBounds.hxx>
00037 #include <HLRBRep_HLRToShape.hxx>
00038 #include <gp_Ax2.hxx>
00039 #include <gp_Pnt.hxx>
00040 #include <gp_Dir.hxx>
00041 #include <Poly_Polygon3D.hxx>
00042 #include <Poly_Triangulation.hxx>
00043 #include <Poly_PolygonOnTriangulation.hxx>
00044 #include <TopoDS.hxx>
00045 #include <TopoDS_Face.hxx>
00046 #include <TopoDS_Edge.hxx>
00047 #include <TopoDS_Vertex.hxx>
00048 #include <TopExp.hxx>
00049 #include <TopExp_Explorer.hxx>
00050 #include <TopTools_IndexedMapOfShape.hxx>
00051 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
00052 #include <TopTools_ListOfShape.hxx>
00053 #include <TColgp_Array1OfPnt2d.hxx>
00054 #include <BRep_Tool.hxx>
00055 #include <BRepMesh.hxx>
00056
00057
00058 #include <Base/Exception.h>
00059 #include <Base/FileInfo.h>
00060 #include <Mod/Part/App/PartFeature.h>
00061
00062 #include "FeatureViewPart.h"
00063 #include "ProjectionAlgos.h"
00064
00065 using namespace Drawing;
00066 using namespace std;
00067
00068
00069
00070
00071
00072
00073 PROPERTY_SOURCE(Drawing::FeatureViewPart, Drawing::FeatureView)
00074
00075
00076 FeatureViewPart::FeatureViewPart(void)
00077 {
00078 static const char *group = "Shape view";
00079
00080 ADD_PROPERTY_TYPE(Direction ,(0,0,1.0),group,App::Prop_None,"Projection direction");
00081 ADD_PROPERTY_TYPE(Source ,(0),group,App::Prop_None,"Shape to view");
00082 ADD_PROPERTY_TYPE(ShowHiddenLines ,(false),group,App::Prop_None,"Control the appearance of the dashed hidden lines");
00083 ADD_PROPERTY_TYPE(ShowSmoothLines ,(false),group,App::Prop_None,"Control the appearance of the smooth lines");
00084 }
00085
00086 FeatureViewPart::~FeatureViewPart()
00087 {
00088 }
00089
00090 #if 0
00091
00092 App::DocumentObjectExecReturn *FeatureViewPart::execute(void)
00093 {
00094 std::stringstream result;
00095 std::string ViewName = Label.getValue();
00096
00097 App::DocumentObject* link = Source.getValue();
00098 if (!link)
00099 return new App::DocumentObjectExecReturn("No object linked");
00100 if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
00101 return new App::DocumentObjectExecReturn("Linked object is not a Part object");
00102 TopoDS_Shape shape = static_cast<Part::Feature*>(link)->Shape.getShape()._Shape;
00103 if (shape.IsNull())
00104 return new App::DocumentObjectExecReturn("Linked shape object is empty");
00105
00106 Handle( HLRBRep_Algo ) brep_hlr = new HLRBRep_Algo;
00107 brep_hlr->Add( shape );
00108
00109 gp_Ax2 transform(gp_Pnt(0,0,0),gp_Dir(0,0,1));
00110 HLRAlgo_Projector projector( transform );
00111 brep_hlr->Projector( projector );
00112 brep_hlr->Update();
00113 brep_hlr->Hide();
00114
00115
00116 HLRBRep_HLRToShape shapes( brep_hlr );
00117
00118 TopoDS_Shape VisiblyEdges;
00119 VisiblyEdges = shapes.VCompound();
00120
00121 TopoDS_Shape HiddenEdges;
00122 HiddenEdges = shapes.HCompound();
00123
00124 BRepMesh::Mesh(VisiblyEdges,0.1);
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 result << "<g"
00138 << " id=\"" << ViewName << "\"" << endl
00139 << " stroke=\"rgb(0, 0, 0)\"" << endl
00140 << " stroke-width=\"0.35\"" << endl
00141 << " stroke-linecap=\"butt\"" << endl
00142 << " stroke-linejoin=\"miter\"" << endl
00143 << " transform=\"translate("<< X.getValue()<<","<<Y.getValue()<<") scale("<< Scale.getValue()<<","<<Scale.getValue()<<")\"" << endl
00144 << " fill=\"none\"" << endl
00145 << " >" << endl;
00146
00147 TopExp_Explorer edges( VisiblyEdges, TopAbs_EDGE );
00148 for (int i = 1 ; edges.More(); edges.Next(),i++ ) {
00149 TopoDS_Edge edge = TopoDS::Edge( edges.Current() );
00150 TopLoc_Location location;
00151 Handle( Poly_Polygon3D ) polygon = BRep_Tool::Polygon3D( edge, location );
00152 if ( !polygon.IsNull() ) {
00153 const TColgp_Array1OfPnt& nodes = polygon->Nodes();
00154 char c = 'M';
00155 result << "<path id= \"" << ViewName << i << "\" d=\" ";
00156 for ( int i = nodes.Lower(); i<= nodes.Upper(); i++ ){
00157 result << c << " " << nodes(i).X() << " " << nodes(i).Y()<< " " ;
00158 c = 'L';
00159 }
00160 result << "\" />" << endl;
00161 }
00162 }
00163
00164 result << "</g>" << endl;
00165
00166
00167 ViewResult.setValue(result.str().c_str());
00168
00169 return App::DocumentObject::StdReturn;
00170 }
00171 #else
00172 App::DocumentObjectExecReturn *FeatureViewPart::execute(void)
00173 {
00174 std::stringstream result;
00175 std::string ViewName = Label.getValue();
00176
00177 App::DocumentObject* link = Source.getValue();
00178 if (!link)
00179 return new App::DocumentObjectExecReturn("No object linked");
00180 if (!link->getTypeId().isDerivedFrom(Part::Feature::getClassTypeId()))
00181 return new App::DocumentObjectExecReturn("Linked object is not a Part object");
00182 TopoDS_Shape shape = static_cast<Part::Feature*>(link)->Shape.getShape()._Shape;
00183 if (shape.IsNull())
00184 return new App::DocumentObjectExecReturn("Linked shape object is empty");
00185 Base::Vector3f Dir = Direction.getValue();
00186 bool hidden = ShowHiddenLines.getValue();
00187 bool smooth = ShowSmoothLines.getValue();
00188
00189 try {
00190 ProjectionAlgos Alg(ProjectionAlgos::invertY(shape),Dir);
00191 result << "<g"
00192 << " id=\"" << ViewName << "\"" << endl
00193 << " transform=\"rotate("<< Rotation.getValue() << ","<< X.getValue()<<","<<Y.getValue()<<") translate("<< X.getValue()<<","<<Y.getValue()<<") scale("<< Scale.getValue()<<","<<Scale.getValue()<<")\"" << endl
00194 << " >" << endl;
00195
00196 ProjectionAlgos::SvgExtractionType type = ProjectionAlgos::Plain;
00197 if (hidden) type = (ProjectionAlgos::SvgExtractionType)(type|ProjectionAlgos::WithHidden);
00198 if (smooth) type = (ProjectionAlgos::SvgExtractionType)(type|ProjectionAlgos::WithSmooth);
00199 result << Alg.getSVG(type, this->Scale.getValue());
00200
00201 result << "</g>" << endl;
00202
00203
00204 ViewResult.setValue(result.str().c_str());
00205
00206 return App::DocumentObject::StdReturn;
00207 }
00208 catch (Standard_Failure) {
00209 Handle_Standard_Failure e = Standard_Failure::Caught();
00210 return new App::DocumentObjectExecReturn(e->GetMessageString());
00211 }
00212 }
00213
00214 #endif
00215
00216
00217
00218
00219 namespace App {
00221 PROPERTY_SOURCE_TEMPLATE(Drawing::FeatureViewPartPython, Drawing::FeatureViewPart)
00222 template<> const char* Drawing::FeatureViewPartPython::getViewProviderName(void) const {
00223 return "DrawingGui::ViewProviderDrawingView";
00224 }
00226
00227
00228 template class DrawingExport FeaturePythonT<Drawing::FeatureViewPart>;
00229 }