aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/views/GestureOverlay.tsx81
-rw-r--r--src/client/views/InkTranscription.tsx6
2 files changed, 64 insertions, 23 deletions
diff --git a/src/client/views/GestureOverlay.tsx b/src/client/views/GestureOverlay.tsx
index abb8445dc..ec94102d7 100644
--- a/src/client/views/GestureOverlay.tsx
+++ b/src/client/views/GestureOverlay.tsx
@@ -7,6 +7,7 @@ import { emptyFunction } from '../../Utils';
import { Doc, Opt } from '../../fields/Doc';
import { InkData, InkField, InkTool } from '../../fields/InkField';
import { NumCast } from '../../fields/Types';
+import { Docs } from '../documents/Documents';
import {
ActiveArrowEnd,
ActiveArrowScale,
@@ -33,6 +34,8 @@ import { ObservableReactComponent } from './ObservableReactComponent';
import { ActiveFillColor, DocumentView } from './nodes/DocumentView';
import { CollectionFreeFormView } from './collections/collectionFreeForm';
import { InkingStroke } from './InkingStroke';
+import { NullLiteral } from 'typescript';
+import { isNull } from 'lodash';
export enum ToolglassTools {
InkToText = 'inktotext',
IgnoreGesture = 'ignoregesture',
@@ -138,7 +141,7 @@ export class GestureOverlay extends ObservableReactComponent<React.PropsWithChil
let cuspBooleanArray: boolean[] = [];
let docsToDelete: Doc[] = [];
const childDocs = (ffView?.ComponentView as CollectionFreeFormView).childDocs;
- childDocs.map(doc => DocumentView.getDocumentView(doc, DocumentView.getDocumentView(doc))).filter(inkView => inkView?.ComponentView instanceof InkingStroke);
+ childDocs.filter(doc => doc.type === 'ink').map(doc => DocumentView.getDocumentView(doc, DocumentView.getDocumentView(doc)));
if ((ffView?.ComponentView as CollectionFreeFormView).childDocs) {
if (cuspArray.length > 4) {
console.log('there are enough cusps');
@@ -294,16 +297,17 @@ export class GestureOverlay extends ObservableReactComponent<React.PropsWithChil
break;
case Gestures.RightAngle:
this.convertToText();
+ this._points = [];
console.log('RightAngle');
+ return;
default:
}
}
-
- // if no gesture (or if the gesture was unsuccessful), "dry" the stroke into an ink document
if (this.isScribble(points)) {
this._points = [];
return;
}
+ // if no gesture (or if the gesture was unsuccessful), "dry" the stroke into an ink document
if (!actionPerformed) {
const newPoints = this._points.reduce((p, pts) => {
p.push([pts.X, pts.Y]);
@@ -327,7 +331,6 @@ export class GestureOverlay extends ObservableReactComponent<React.PropsWithChil
this._points.length = 0;
this._points.push(...controlPoints);
this.dispatchGesture(Gestures.Stroke);
- const ffView = DocumentView.allViews().find(view => view.ComponentView instanceof CollectionFreeFormView);
}
}
}
@@ -335,23 +338,61 @@ export class GestureOverlay extends ObservableReactComponent<React.PropsWithChil
};
convertToText() {
const ffView = DocumentView.allViews().find(view => view.ComponentView instanceof CollectionFreeFormView);
- const collectionDocs = (ffView?.ComponentView as CollectionFreeFormView).childDocs.filter(doc => doc.type === 'collection').filter(doc => doc.transcription);
- (ffView?.ComponentView as CollectionFreeFormView).childDocs.forEach(doc => {
- console.log(doc.x);
- console.log(doc.y);
- console.log(doc.width);
- console.log(doc.height);
- if (typeof doc.width === 'number' && typeof doc.height === 'number' && typeof doc.x === 'number' && typeof doc.y === 'number') {
- const rect1 = { minX: doc.x, maxX: doc.x + doc.width, minY: doc.y, maxY: doc.y + doc.height };
- console.log(rect1);
- console.log(this.getExtremeCoordinates(this._points));
- const points = this._points.map(p => ({ X: p.X, Y: p.Y }));
- console.log(points);
- if (this.isRectangleOverlap(rect1, this.getExtremeCoordinates(this._points))) {
- console.log('somethings in');
+ let docsToBeConverted: Doc[] = [];
+ let minX = 999999999;
+ let maxX = -999999999;
+ let minY = 999999999;
+ let maxY = -999999999;
+ (ffView?.ComponentView as CollectionFreeFormView).childDocs
+ .filter(doc => doc.type === 'collection')
+ .forEach(doc => {
+ if (typeof doc.width === 'number' && typeof doc.height === 'number' && typeof doc.x === 'number' && typeof doc.y === 'number') {
+ const bounds = DocumentView.getDocumentView(doc)?.getBounds;
+ console.log(DocumentView.getDocumentView(doc));
+ console.log(bounds);
+ if (bounds) {
+ const rect1 = { minX: bounds.left, maxX: bounds.right, minY: bounds.top, maxY: bounds.bottom };
+ console.log(rect1);
+ console.log(this.getExtremeCoordinates(this._points));
+ const points = this._points.map(p => ({ X: p.X, Y: p.Y }));
+ console.log(points);
+ if (this.isRectangleOverlap(rect1, this.getExtremeCoordinates(this._points))) {
+ if (doc.x < minX) {
+ minX = doc.x;
+ }
+ if (doc.x > maxX) {
+ maxX = doc.x;
+ }
+ if (doc.y < minY) {
+ minY = doc.y;
+ }
+ if (doc.y + doc.height > maxY) {
+ maxY = doc.y + doc.height;
+ }
+ const newDoc = Docs.Create.TextDocument(doc.transcription as string, { title: '', x: doc.x as number, y: minY });
+ newDoc.height = doc.height;
+ newDoc.width = doc.width;
+ if (ffView?.ComponentView?.addDocument && ffView?.ComponentView?.removeDocument) {
+ ffView.ComponentView.addDocument(newDoc);
+ ffView.ComponentView.removeDocument(doc);
+ }
+ //docsToBeConverted.push(doc);
+ }
+ }
}
- }
- });
+ });
+ // const collectionDoc = Docs.Create.FreeformDocument(docsToBeConverted, { title: '', x: minX as number, y: maxY as number });
+ // collectionDoc.height = 50;
+ // collectionDoc.width = 50;
+ // if (ffView?.ComponentView?.addDocument) {
+ // ffView.ComponentView.addDocument(collectionDoc);
+ // }
+ // DocumentView.getDocumentView(collectionDoc)?.ComponentView?.updateIcon;
+ // const newDoc = Docs.Create.TextDocument(doc.transcription as string, { title: '', x: doc.x as number, y: maxY });
+ // newDoc.height = 50;
+ // if (ffView?.ComponentView?.addDocument) {
+ // ffView.ComponentView.addDocument(newDoc);
+ // }
}
getNumberOfCusps(points: any) {
let arrayOfPoints: any[] = [];
diff --git a/src/client/views/InkTranscription.tsx b/src/client/views/InkTranscription.tsx
index a7af11463..e66bd9dda 100644
--- a/src/client/views/InkTranscription.tsx
+++ b/src/client/views/InkTranscription.tsx
@@ -271,8 +271,6 @@ export class InkTranscription extends React.Component {
if (this.currGroup && text) {
DocumentView.getDocumentView(this.currGroup)?.ComponentView?.updateIcon?.();
- this.currGroup.transcription = text;
- this.currGroup.title = text;
let image = await this.getIcon();
const pathname = image?.url.href as string;
console.log(image?.url);
@@ -289,10 +287,12 @@ export class InkTranscription extends React.Component {
console.log('bad things have happened');
}
const textBoxText = 'iink: ' + text + '\n' + '\n' + 'ChatGPT: ' + response;
+ this.currGroup.transcription = response;
+ this.currGroup.title = response;
if (!this.currGroup.hasTextBox) {
const newDoc = Docs.Create.TextDocument(textBoxText, { title: '', x: this.currGroup.x as number, y: (this.currGroup.y as number) + (this.currGroup.height as number) });
newDoc.height = 200;
- this.collectionFreeForm?.addDocument(newDoc);
+ //this.collectionFreeForm?.addDocument(newDoc);
this.currGroup.hasTextBox = true;
}
ref.editor.clear();