-# Demo script for dimensions
-puts "Dimensions demo: it shows capability of OCC to create different kinds "
-puts "of dimensions (linear and angular) with 2D or 3D text."
+#Category: Demos
+#Title: Dimensions in 3d viewer
-set dispScriptFile [file normalize [info script]]
-set scriptFolder [file dirname $dispScriptFile]
+# Dimensions demo
+#
+# It shows capability of OCC to create different kinds
+# of dimensions (linear and angular) with 2D or 3D text.
set aTopLoc [locate_data_file occ/Top.brep]
set aBotLoc [locate_data_file occ/Bottom.brep]
set aHatch [locate_data_file images/hatch_1.png]
-if { ![file exist "$aTopLoc"] || ![file exist "$aBotLoc"] } {
- puts "No model file in current directory!"
- puts "Please put Bottom.brep and Top.brep in current directory and try again"
-}
-
pload MODELING VISUALIZATION
+
+puts "Importing shapes..."
restore $aTopLoc a
restore $aBotLoc b
+
vinit View1 w=768 h=768
vclear
vsetdispmode 0
vsetcolorbg 255 255 255
vbottom
-# Get cut projection
+puts "Getting cut projection..."
box bb -150 -250 0 150 250 100
bsection bs b bb
bsection as a bb
set anAEdges [explode as E]
set aBEbges [explode bs E]
-#foreach e [concat $anAEdges $aBEbges] { vdisplay $e }
set anArrAngle [expr 3.14 * 12.0 / 180.0]
-set aList {das_7 dbs_27 dbs_6 dbs_19 das_25 das_26 dbs_22 das_43 das_12 das_41 dbs_39 dbs_59 das_3944 dbs_1826 das_4843}
-
-vdimension dbs_19 -length -shapes bs_27 -plane xoy -color black -flyout -15
-vdimension dbs_6 -length -shapes bs_14 -plane xoy -color black -flyout 15
-vdimension dbs_27 -length -shapes bs_28 -plane xoy -color black -label right -flyout -27
-vdimension das_7 -length -shapes as_7 -plane xoy -color black -flyout -20
-vdimension das_25 -length -shapes as_28 -plane xoy -color black -flyout -15
-vdimension das_26 -length -shapes as_18 -plane xoy -color black -flyout 30
-vdimension dbs_22 -length -shapes bs_20 -plane xoy -color black -flyout -20
-vdimension das_43 -length -shapes as_43 -plane xoy -color black -flyout 55 -label right
-vdimension das_12 -length -shapes as_12 -plane xoy -color black -flyout 35 -label right
-vdimension das_41 -length -shapes as_40 -plane xoy -color black -flyout 15
-
-vdimension dbs_39 -radius -shapes bs_45 -color black -label right
-vdimension dbs_59 -radius -shapes bs_63 -color black
-
-vdimension das_3944 -angle -shapes as_38 as_49 -color black
-vdimension dbs_1826 -angle -shapes bs_24 bs_25 -color black
-vdimension das_4843 -angle -shapes as_48 as_43 -color black
+# Form dimension names list to set parameters with vdimparam command
+set aList {rd_1 rd_2 ad_1 ad_2 ad_3}
+for {set i 1} {$i <= 10} {incr i} {
+lappend aList ld_$i
+}
+puts "Creating dimensions..."
+vdimension ld_1 -length -shapes bs_27 -plane xoy -color black -flyout -15
+vdimension ld_2 -length -shapes bs_14 -plane xoy -color black -flyout 15
+vdimension ld_3 -length -shapes bs_28 -plane xoy -color black -label right -flyout -27
+vdimension ld_4 -length -shapes as_7 -plane xoy -color black -flyout -20
+vdimension ld_5 -length -shapes as_28 -plane xoy -color black -flyout -15
+vdimension ld_6 -length -shapes as_18 -plane xoy -color black -flyout 30
+vdimension ld_7 -length -shapes bs_20 -plane xoy -color black -flyout -20
+vdimension ld_8 -length -shapes as_43 -plane xoy -color black -flyout 55 -label right
+vdimension ld_9 -length -shapes as_12 -plane xoy -color black -flyout 35 -label right
+vdimension ld_10 -length -shapes as_40 -plane xoy -color black -flyout 15
+
+vdimension rd_1 -radius -shapes bs_45 -color black -label right
+vdimension rd_2 -radius -shapes bs_63 -color black
+
+vdimension ad_1 -angle -shapes as_38 as_49 -color black
+vdimension ad_2 -angle -shapes bs_24 bs_25 -color black
+vdimension ad_3 -angle -shapes as_48 as_43 -color black
+
+puts "Changing text and arrow paramaters of dimensions..."
foreach i $aList {
- vdimparam $i text=3d textsize=6 textmode=s arlength=4 arangle=$anArrAngle
+ vdimparam $i -text 3d sh 6 -arrowlength 4 -arrowangle $anArrAngle
}
-# Final fit
-foreach e [concat $anAEdges $aBEbges] {
- vremove $e
-}
vfit
+puts "Displaying exported shapes..."
vdisplay a b
vsetdispmode a 1
vsetdispmode b 1
vaspects a -setmaterial steel
vaspects b -setmaterial bronze
-# set clipping plane
+puts "Clipping shapes for better view..."
vclipplane create pa
vclipplane change pa equation 0 0 1 0
vclipplane change pa capping on
vclipplane change pa capping color 0.9 0.9 0.9
-#vclipplane change pa capping hatch on
vclipplane set pa object a
vclipplane create pb
vclipplane change pb equation 0 0 1 0
vclipplane change pb capping on
vclipplane change pb capping color 1.0 0.8 0.0
-#vclipplane change pb capping hatch on
vclipplane set pb object b
vsettexturemode Driver1/Viewer1/View1 2
vclipplane change pb capping texname $aHatch
vclipplane change pb capping texscale 0.05 0.05
-# nice view
vbottom
vrotate -0.3 -0.3 0
vfit
vzoom 1.2
+
+puts "Done."
\ No newline at end of file
}
else if (aParam.IsEqual ("-arrow"))
{
- do
- {
- anIt++;
- TCollection_AsciiString aParam (theArgVec[anIt]);
- aParam.LowerCase();
+ TCollection_AsciiString aParam (theArgVec[++anIt]);
+ aParam.LowerCase();
- if (aParam == "external") { theAspect->SetArrowOrientation (Prs3d_DAO_External); }
- if (aParam == "internal") { theAspect->SetArrowOrientation (Prs3d_DAO_Internal); }
- if (aParam == "fit") { theAspect->SetArrowOrientation (Prs3d_DAO_Fit); }
- if (aParam.IsRealValue()) { theAspect->ArrowAspect()->SetLength (Draw::Atof (aParam.ToCString())); }
+ if (aParam == "external") { theAspect->SetArrowOrientation (Prs3d_DAO_External); }
+ if (aParam == "internal") { theAspect->SetArrowOrientation (Prs3d_DAO_Internal); }
+ if (aParam == "fit") { theAspect->SetArrowOrientation (Prs3d_DAO_Fit); }
+ }
+ else if (aParam.IsEqual ("-arrowlength") || aParam.IsEqual ("-arlen"))
+ {
+ TCollection_AsciiString aValue (theArgVec[++anIt]);
+ if (!aValue.IsRealValue())
+ {
+ std::cerr << "Error: arrow lenght should be float degree value.\n";
+ return 1;
}
- while (anIt + 1 < theArgNum && theArgVec[anIt + 1][0] != '-');
+ theAspect->ArrowAspect()->SetLength (Draw::Atof (aValue.ToCString()));
}
- else if (aParam.IsEqual ("-arrowangle"))
+ else if (aParam.IsEqual ("-arrowangle") || aParam.IsEqual ("-arangle"))
{
TCollection_AsciiString aValue (theArgVec[++anIt]);
if (!aValue.IsRealValue())
TopoDS_Edge anEdge = TopoDS::Edge ((Handle(AIS_Shape)::DownCast(aShapes.First()))->Shape());
TopoDS_Vertex aFirst, aSecond;
TopExp::Vertices (anEdge, aFirst, aSecond);
- aWorkingPlane.SetLocation (BRep_Tool::Pnt(aFirst));
aDim = new AIS_LengthDimension (anEdge, aWorkingPlane);
+
+ // Move standard plane (XOY, YOZ or ZOX) to the first point to make it working for dimension
+ aWorkingPlane.SetLocation (Handle(AIS_LengthDimension)::DownCast (aDim)->FirstPoint());
}
else if (aShapes.Extent() == 2)
{
if (!aDim->IsValid())
{
std::cerr << theArgs[0] << ":dimension geometry is invalid, " << aDimType.ToCString()
- << " dimension can't be build on input shapes.\n";
+ << " dimension can't be built on input shapes.\n";
return 1;
}
theCommands.Add("vdimension",
"vdimension name {-angle|-length|-radius|-diameter} -shapes shape1 [shape2 [shape3]]\n"
- "[-text 3d|2d,wf|sh|wireframe|shading,Size]\n"
- "[-label left|right|hcenter|hfit,top|bottom|vcenter|vfit]\n"
- "[-arrow external|internal|fit,Length(int)]\n"
- "[-arrowangle ArrowAngle(degrees)]\n"
+ "[-text 3d|2d wf|sh|wireframe|shading IntegerSize]\n"
+ "[-label left|right|hcenter|hfit top|bottom|vcenter|vfit]\n"
+ "[-arrow external|internal|fit]\n"
+ "[{-arrowlength|-arlen} RealArrowLength]\n"
+ "[{-arrowangle|-arangle} ArrowAngle(degrees)]\n"
"[-plane xoy|yoz|zox]\n"
"[-flyout FloatValue -extension FloatValue]\n"
"[-value CustomNumberValue]\n"
theCommands.Add("vdimparam",
"vdimparam name"
- "[-text 3d|2d,wf|sh|wireframe|shading,Size]\n"
- "[-label left|right|hcenter|hfit,top|bottom|vcenter|vfit]\n"
- "[-arrow external|internal|fit,Length(int)]\n"
- "[-arrowangle ArrowAngle(degrees)]\n"
+ "[-text 3d|2d wf|sh|wireframe|shading IntegerSize]\n"
+ "[-label left|right|hcenter|hfit top|bottom|vcenter|vfit]\n"
+ "[-arrow external|internal|fit]\n"
+ "[{-arrowlength|-arlen} RealArrowLength]\n"
+ "[{-arrowangle|-arangle} ArrowAngle(degrees)]\n"
"[-plane xoy|yoz|zox]\n"
"[-flyout FloatValue -extension FloatValue]\n"
"[-value CustomNumberValue]\n"