Code: Select all
dimaligned
0,0
100,0
100
Moderator: andrew
Code: Select all
dimaligned
0,0
100,0
100
Code: Select all
function drawHorizontalDim(extensionPoint1, extensionPoint2, definitionPoint)
{
include("scripts/Draw/Dimension/DimRotated/DimRotated.js");
var di = getDocumentInterface();
var doc = this.getDocument();
// create and initialize tool:
var a = new DimRotated();
// Amend getOperation for absence of scale value in toolbar
a.getOperation = function(preview) {
if (!this.data.isValid()) {
return undefined;
}
var doc = this.getDocument();
var scale = 1;
var scaled_data = this.data;
scaled_data.setLinearFactor(1/scale);
var entity = new RDimRotatedEntity(doc, scaled_data);
if (!isEntity(entity)) {
return undefined;
}
return new RAddObjectOperation(entity, this.getToolTitle());
};
a.setDocumentInterface(di);
a.data.setExtensionPoint1(new RVector(extensionPoint1));
a.data.setExtensionPoint2(new RVector(extensionPoint2));
a.data.setDefinitionPoint(new RVector(definitionPoint));
// Locks the rotation of the measurement at 0
a.data.setRotation(0.0);
// run operation on current document:
var op = a.getOperation(false);
di.applyOperation(op);
}
Code: Select all
function drawAlignedDim(extensionPoint1, extensionPoint2, definitionPoint)
{
include("scripts/Draw/Dimension/DimAligned/DimAligned.js");
var di = getDocumentInterface();
var doc = this.getDocument();
// create and initialize tool:
var a = new DimAligned();
// Amend getOperation for absence of scale value in toolbar
a.getOperation = function(preview) {
if (!this.data.isValid()) {
return undefined;
}
var doc = this.getDocument();
var scale = 1;
var scaled_data = this.data;
scaled_data.setLinearFactor(1/scale);
var entity = new RDimAlignedEntity(doc, scaled_data);
if (!isEntity(entity)) {
return undefined;
}
return new RAddObjectOperation(entity, this.getToolTitle());
};
a.setDocumentInterface(di);
a.data.setExtensionPoint1(new RVector(extensionPoint1));
a.data.setExtensionPoint2(new RVector(extensionPoint2));
a.data.setDefinitionPoint(new RVector(definitionPoint));
// run operation on current document:
var op = a.getOperation(false);
di.applyOperation(op);
}
Code: Select all
function drawVerticalDim(extensionPoint1, extensionPoint2, definitionPoint)
{
include("scripts/Draw/Dimension/DimRotated/DimRotated.js");
var di = getDocumentInterface();
var doc = this.getDocument();
// create and initialize tool:
var a = new DimRotated();
// Amend getOperation for absence of scale value in toolbar
a.getOperation = function(preview) {
if (!this.data.isValid()) {
return undefined;
}
var doc = this.getDocument();
var scale = 1;
var scaled_data = this.data;
scaled_data.setLinearFactor(1/scale);
var entity = new RDimRotatedEntity(doc, scaled_data);
if (!isEntity(entity)) {
return undefined;
}
return new RAddObjectOperation(entity, this.getToolTitle());
};
a.setDocumentInterface(di);
a.data.setExtensionPoint1(new RVector(extensionPoint1));
a.data.setExtensionPoint2(new RVector(extensionPoint2));
a.data.setDefinitionPoint(new RVector(definitionPoint));
a.data.setRotation(Math.PI / 2);
// run operation on current document:
var op = a.getOperation(false);
di.applyOperation(op);
}
Code: Select all
function drawAngularDim(firstEntity, secondEntity, dimArcPosition)
{
include("scripts/Draw/Dimension/DimAngular/DimAngular.js");
var di = getDocumentInterface();
var doc = this.getDocument();
// create and initialize tool:
var a = new DimAngular();
a.setDocumentInterface(di);
a.firstEntity = firstEntity;
a.secondEntity = secondEntity;
a.dimArcPosition = dimArcPosition;
// run operation on current document:
var op = a.getOperation(false);
di.applyOperation(op);
}
At first glance, way too little parsed.
It is correct that DimHorizontal & DimVertical are both DimRotated.
I set this.data.setRotation in my functions and thought that would be enough but evidently not. I have just rewritten them to use the DimHorizontal.js and DimVertical.js, rather than both of them using DimRotated.js and they both work now, so I must have missed something before.
Code: Select all
function drawHorizontalDim(extensionPoint1, extensionPoint2, definitionPoint)
{
include("scripts/Draw/Dimension/DimHorizontal/DimHorizontal.js");
var di = getDocumentInterface();
var doc = this.getDocument();
// create and initialize tool:
var a = new DimHorizontal();
// Amend getOperation for absence of scale value in toolbar
a.getOperation = function(preview) {
if (!this.data.isValid()) {
return undefined;
}
var doc = this.getDocument();
var scale = 1;
var scaled_data = this.data;
scaled_data.setLinearFactor(1/scale);
var entity = new RDimRotatedEntity(doc, scaled_data);
if (!isEntity(entity)) {
return undefined;
}
return new RAddObjectOperation(entity, this.getToolTitle());
};
a.setDocumentInterface(di);
a.data.setExtensionPoint1(new RVector(extensionPoint1));
a.data.setExtensionPoint2(new RVector(extensionPoint2));
a.data.setDefinitionPoint(new RVector(definitionPoint));
//a.data.setRotation(0.0);
// run operation on current document:
var op = a.getOperation(false);
di.applyOperation(op);
}
Code: Select all
function drawVerticalDim(extensionPoint1, extensionPoint2, definitionPoint)
{
include("scripts/Draw/Dimension/DimVertical/DimVertical.js");
var di = getDocumentInterface();
var doc = this.getDocument();
// create and initialize tool:
var a = new DimVertical();
// Amend getOperation for absence of scale value in toolbar
a.getOperation = function(preview) {
if (!this.data.isValid()) {
return undefined;
}
var doc = this.getDocument();
var scale = 1;
var scaled_data = this.data;
scaled_data.setLinearFactor(1/scale);
var entity = new RDimRotatedEntity(doc, scaled_data);
if (!isEntity(entity)) {
return undefined;
}
return new RAddObjectOperation(entity, this.getToolTitle());
};
a.setDocumentInterface(di);
a.data.setExtensionPoint1(new RVector(extensionPoint1));
a.data.setExtensionPoint2(new RVector(extensionPoint2));
a.data.setDefinitionPoint(new RVector(definitionPoint));
// run operation on current document:
var op = a.getOperation(false);
di.applyOperation(op);
}
//! [drawVerticalDim]
I have been creating RLines, RLineData and RLineEntitys and passing them to the function as arguments, hoping that I could do the choosing for it, but so far it hasn't worked.CVH wrote: ↑Mon Mar 30, 2020 7:21 amWhere are those 1ste and 2nd entity defined?
In the switch from DimAngular.prototype.pickEntity one can see that Qcad looks
for the ClosestSimpleShape near the position.
So Qcad is still picking entities....
The data that is really needed is collected in:
this.data3P for a new RDimAngular3PEntity
or in this.data2L for a new RDimAngular2LEntity.
That is the essence of my reply.