Skip to content

Commit

Permalink
fix FS#1052 - (Isometric) projection: poor preview performance
Browse files Browse the repository at this point in the history
fix several potential script exceptions
  • Loading branch information
qcad committed May 22, 2014
1 parent 308c84f commit 0fda395
Show file tree
Hide file tree
Showing 16 changed files with 136 additions and 39 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Makefile.Debug
Makefile.Release
*.pro.user
.qmake.cache
*.xcodeproj

# Mac:
.DS_Store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,12 @@ EllipseInscribedQuad.prototype.getOperation = function(preview) {

var doc = this.getDocument();

return new RAddObjectOperation(shapeToEntity(doc, shape));
var e = shapeToEntity(doc, shape);
if (isNull(e)) {
return undefined;
}

return new RAddObjectOperation(e);
};

EllipseInscribedQuad.prototype.getHighlightedEntities = function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,12 @@ LineOrthogonalTangent.prototype.getOperation = function(preview) {
return undefined;
}

var op = new RAddObjectsOperation();
op.addObject(shapeToEntity(doc, tangent));
return op;
var e = shapeToEntity(doc, tangent);
if (isNull(e)) {
return undefined;
}

return new RAddObjectsOperation(e);
};

LineOrthogonalTangent.prototype.getTangent = function() {
Expand Down
5 changes: 5 additions & 0 deletions scripts/ImportExport/SvgImporter/SvgImporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ SvgImporter.prototype.importShape = function(shape) {
shape.scale(new RVector(this.resolutionScale, this.resolutionScale));

var entity = shapeToEntity(this.getDocument(), shape);

if (isNull(entity)) {
return;
}

if (!isNull(this.style.stroke)) {
entity.setColor(new RColor(this.style.stroke));
}
Expand Down
4 changes: 3 additions & 1 deletion scripts/Information/Information.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ Information.prototype.addShape = function(op, shape, preview) {
else {
if (!isNull(op)) {
var e = shapeToEntity(this.getDocument(), shape);
op.addObject(e);
if (!isNull(e)) {
op.addObject(e);
}
}
}
};
Expand Down
18 changes: 12 additions & 6 deletions scripts/Modify/BreakOut/BreakOut.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,10 @@ BreakOut.prototype.getOperation = function(preview) {
if (!isNull(newSegments[2])) {
if (this.extend || !this.removeSegment) {
e = shapeToEntity(this.entity.getDocument(), newSegments[2]);
e.copyAttributesFrom(this.entity.data());
op.addObject(e, false);
if (!isNull(e)) {
e.copyAttributesFrom(this.entity.data());
op.addObject(e, false);
}
}
}
}
Expand All @@ -227,14 +229,18 @@ BreakOut.prototype.getOperation = function(preview) {
if (!this.extend) {
if (!isNull(newSegments[0])) {
e = shapeToEntity(this.entity.getDocument(), newSegments[0]);
e.copyAttributesFrom(this.entity.data());
op.addObject(e, false);
if (!isNull(e)) {
e.copyAttributesFrom(this.entity.data());
op.addObject(e, false);
}
}

if (!isNull(newSegments[1])/* && !this.removeSegment*/) {
e = shapeToEntity(this.entity.getDocument(), newSegments[1])
e.copyAttributesFrom(this.entity.data());
op.addObject(e, false);
if (!isNull(e)) {
e.copyAttributesFrom(this.entity.data());
op.addObject(e, false);
}
}
}

Expand Down
18 changes: 12 additions & 6 deletions scripts/Modify/BreakOutManual/BreakOutManual.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,10 @@ BreakOutManual.prototype.getOperation = function(preview) {
op.deleteObject(this.entity);
if (!isNull(newSegments[2])) {
e = shapeToEntity(this.entity.getDocument(), newSegments[2]);
e.copyAttributesFrom(this.entity.data());
op.addObject(e, false);
if (!isNull(e)) {
e.copyAttributesFrom(this.entity.data());
op.addObject(e, false);
}
}
}

Expand All @@ -272,14 +274,18 @@ BreakOutManual.prototype.getOperation = function(preview) {

if (!isNull(newSegments[0])) {
e = shapeToEntity(this.entity.getDocument(), newSegments[0]);
e.copyAttributesFrom(this.entity.data());
op.addObject(e, false);
if (!isNull(e)) {
e.copyAttributesFrom(this.entity.data());
op.addObject(e, false);
}
}

if (!isNull(newSegments[1])) {
e = shapeToEntity(this.entity.getDocument(), newSegments[1])
e.copyAttributesFrom(this.entity.data());
op.addObject(e, false);
if (!isNull(e)) {
e.copyAttributesFrom(this.entity.data());
op.addObject(e, false);
}
}

return op;
Expand Down
6 changes: 4 additions & 2 deletions scripts/Modify/Divide/Divide.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,10 @@ Divide.prototype.getOperation = function(preview) {
isEllipseShape(shape2) || isSplineShape(shape2)) {

e = shapeToEntity(this.entity.getDocument(), shape2);
e.copyAttributesFrom(this.entity.data());
op.addObject(e, false);
if (!isNull(e)) {
e.copyAttributesFrom(this.entity.data());
op.addObject(e, false);
}
}
}
return op;
Expand Down
8 changes: 5 additions & 3 deletions scripts/Modify/Explode/Explode.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,11 @@ Explode.prototype.beginEvent = function() {
for (k=0; k<newShapes.length; k++) {
shape = newShapes[k];
e = shapeToEntity(entity.getDocument(), shape);
e.setSelected(true);
e.copyAttributesFrom(entity.data());
op.addObject(e, false);
if (!isNull(e)) {
e.setSelected(true);
e.copyAttributesFrom(entity.data());
op.addObject(e, false);
}
}

// add entities based on entities that resulted from the explosion:
Expand Down
12 changes: 8 additions & 4 deletions scripts/Modify/Scale/Scale.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,18 @@ Scale.prototype.transform = function(entity, k, op, preview, forceNew) {
);

var e = shapeToEntity(this.getDocument(), shape);
e.copyAttributesFrom(entity);
e.setDrawOrder(entity.getDrawOrder());
e.setSelected(true);
if (!isNull(e)) {
e.copyAttributesFrom(entity);
e.setDrawOrder(entity.getDrawOrder());
e.setSelected(true);
}

if (this.copies===0) {
op.deleteObject(entity);
}
op.addObject(e, this.useCurrentAttributes, forceNew);
if (!isNull(e)) {
op.addObject(e, this.useCurrentAttributes, forceNew);
}
return;
}

Expand Down
58 changes: 51 additions & 7 deletions scripts/Modify/Transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,52 @@ Transform.prototype.verifySelection = function() {
* The callback function 'this.transform(entity, copy number)' is called for
* every selected entity.
*/
Transform.prototype.getOperation = function(preview, selectResult) {
Transform.prototype.getOperation = function(preview, selectResult, cache) {
if (isNull(this.copies)) {
return undefined;
}

if (isNull(selectResult)) {
selectResult = true;
}
if (isNull(cache)) {
cache = false;
}

var di = this.getDocumentInterface();
var document = this.getDocument();
var op, di, ids;

if (cache) {
if (!isNull(this.diTrans) && preview) {
op = new RPasteOperation(this.diTrans.getDocument());
op.setOffset(this.targetPoint)
return op;
}

this.diTrans = new RDocumentInterface(new RDocument(new RMemoryStorage(), new RSpatialIndexNavel()));

//this.diTrans.getDocument().setUnit(this.getDocument().getUnit());
this.diTrans.applyOperation(new RCopyOperation(new RVector(0,0), this.getDocument()));
//this.diTrans.getDocument().setUnit(this.getDocument().getUnit());
di = this.diTrans;
ids = di.getDocument().queryAllEntities();
}
else {
di = this.getDocumentInterface();
ids = di.getDocument().querySelectedEntities();
}

var document = di.getDocument();
var storage = document.getStorage();
var ids = document.querySelectedEntities();
var i, k, id, entity, entityP;
var num = this.copies;
if (num===0) {
num=1;
}

var op = new RAddObjectsOperation();
op = new RAddObjectsOperation();
for (k=1; k<=num; k++) {
for (i=0; i<ids.length; i++) {
if (preview && op.getPreviewCounter()>RSettings.getPreviewEntities()) {
if (!cache && preview && op.getPreviewCounter()>RSettings.getPreviewEntities()) {
break;
}

Expand All @@ -91,15 +114,36 @@ Transform.prototype.getOperation = function(preview, selectResult) {
}
}

this.transform(entity, k, op, preview, this.copies>0);
if (cache) {
op.deleteObject(entity);
this.transform(entity, k, op, preview, true);
}
else {
this.transform(entity, k, op, preview, this.copies>0);
}
}
op.endCycle();
}

if (cache) {
di.applyOperation(op);
}

// deselect original entities, all copies are selected:
if (!preview && selectResult) {
di.deselectEntities(ids);
}

if (cache) {
op = new RPasteOperation(this.diTrans.getDocument());
op.setOffset(this.targetPoint);
}

return op;
};

Transform.prototype.clearCache = function() {
// clear cache:
this.diTrans = undefined;
//Modify.prototype.updatePreview.call(this);
};
Original file line number Diff line number Diff line change
Expand Up @@ -42,35 +42,42 @@ IsoProject.prototype.project = function(p) {

IsoProject.prototype.slotTopChanged = function() {
this.projection = RS.IsoTop;
this.clearCache();
this.updatePreview(true);
};

IsoProject.prototype.slotBottomChanged = function() {
this.projection = RS.IsoBottom;
this.clearCache();
this.updatePreview(true);
};

IsoProject.prototype.slotLeftChanged = function() {
this.projection = RS.IsoLeft;
this.clearCache();
this.updatePreview(true);
};

IsoProject.prototype.slotLeftBackChanged = function() {
this.projection = RS.IsoLeftBack;
this.clearCache();
this.updatePreview(true);
};

IsoProject.prototype.slotRightChanged = function() {
this.projection = RS.IsoRight;
this.clearCache();
this.updatePreview(true);
};

IsoProject.prototype.slotRightBackChanged = function() {
this.projection = RS.IsoRightBack;
this.clearCache();
this.updatePreview(true);
};

IsoProject.prototype.slotTrueScaleChanged = function(v) {
this.trueScale = v;
this.clearCache();
this.updatePreview(true);
};
13 changes: 10 additions & 3 deletions scripts/Projection/Projection.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ Projection.prototype.getOperation = function(preview) {
return undefined;
}

return Transform.prototype.getOperation.call(this, preview, false);
return Transform.prototype.getOperation.call(this, preview, false, true);
};

Projection.prototype.preTransform = function(entity) {
Expand Down Expand Up @@ -253,9 +253,13 @@ Projection.prototype.addTransformedShapes = function(entity, shapes, op, preview
debugger;
}

var e = shapeToEntity(this.getDocument(), s[n]);
var e = shapeToEntity(entity.getDocument(), s[n]);
if (isNull(e)) {
continue;
}

e.copyAttributesFrom(entity);
e.move(this.targetPoint);
//e.move(this.targetPoint);
op.addObject(e, false, forceNew);
}
}
Expand Down Expand Up @@ -499,15 +503,18 @@ Projection.prototype.projectShape = function(shape, preview, trim) {

Projection.prototype.slotRotateCCW = function() {
this.rotation += 90;
this.clearCache();
this.updatePreview(true);
};

Projection.prototype.slotRotateCW = function() {
this.rotation -= 90;
this.clearCache();
this.updatePreview(true);
};

Projection.prototype.slotSegmentLengthChanged = function(l) {
this.segmentLength = l;
this.clearCache();
this.updatePreview(true);
};
3 changes: 3 additions & 0 deletions src/operations/RAddObjectsOperation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ RAddObjectsOperation::RAddObjectsOperation(
}
}

RAddObjectsOperation::~RAddObjectsOperation() {
}

void RAddObjectsOperation::replaceObject(const QSharedPointer<RObject>& object,
bool useCurrentAttributes) {

Expand Down
3 changes: 1 addition & 2 deletions src/operations/RAddObjectsOperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ class QCADOPERATIONS_EXPORT RAddObjectsOperation: public ROperation {
RAddObjectsOperation(bool undoable = true);
RAddObjectsOperation(QList<QSharedPointer<RObject> >& list,
bool useCurrentAttributes = true, bool undoable = true);
virtual ~RAddObjectsOperation() {
}
virtual ~RAddObjectsOperation();

/**
* Adds the given object to this operation or replaces an object
Expand Down
3 changes: 2 additions & 1 deletion src/operations/RMixedOperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class RObject;

/**
* Implementation of an operation that adds, modifies and deletes entities.
*
*
* \obsolete
* \ingroup operations
* \scriptable
*/
Expand Down

0 comments on commit 0fda395

Please sign in to comment.