@@ -9,7 +9,7 @@ import { LoadfileComponent } from './core/modal/loadfile/loadfile.component';
99import { LoginComponent } from './core/modal/login/login.component' ;
1010import { MaterialModal } from './core/modal/material/material.modal' ;
1111import { createCell } from './core/model/cell' ;
12- import { Draft , DraftNode , DraftNodeProxy , FileObj , LoadResponse , Loom , LoomSettings , NodeComponentProxy , SaveObj , TreeNode , TreeNodeProxy } from './core/model/datatypes' ;
12+ import { Draft , DraftNode , DraftNodeProxy , FileObj , IndexedColorImageInstance , IndexedColorMediaProxy , LoadResponse , Loom , LoomSettings , NodeComponentProxy , SaveObj , TreeNode , TreeNodeProxy } from './core/model/datatypes' ;
1313import { defaults , density_units , editor_modes , loom_types , origin_option_list } from './core/model/defaults' ;
1414import { copyDraft , getDraftName , initDraftWithParams } from './core/model/drafts' ;
1515import { copyLoom , copyLoomSettings , getLoomUtilByType } from './core/model/looms' ;
@@ -18,7 +18,7 @@ import { AuthService } from './core/provider/auth.service';
1818import { DesignmodesService } from './core/provider/designmodes.service' ;
1919import { FileService } from './core/provider/file.service' ;
2020import { FilesystemService } from './core/provider/filesystem.service' ;
21- import { ImageService } from './core/provider/image .service' ;
21+ import { MediaService } from './core/provider/media .service' ;
2222import { MaterialsService } from './core/provider/materials.service' ;
2323import { NotesService } from './core/provider/notes.service' ;
2424import { OperationService } from './core/provider/operation.service' ;
@@ -105,7 +105,7 @@ export class AppComponent implements OnInit{
105105 public files : FilesystemService ,
106106 private fs : FileService ,
107107 private http : HttpClient ,
108- private image : ImageService ,
108+ private media : MediaService ,
109109 private ms : MaterialsService ,
110110 public multiselect : MultiselectService ,
111111 private ops : OperationService ,
@@ -194,6 +194,7 @@ export class AppComponent implements OnInit{
194194 this . vs . clearPin ( ) ;
195195 this . vs . clearViewer ( ) ;
196196 this . mixer . clearView ( ) ;
197+ this . media . clearMedia ( ) ;
197198 this . editor . clearAll ( ) ;
198199 this . viewer . clearView ( ) ;
199200 this . tree . clear ( ) ;
@@ -551,8 +552,38 @@ export class AppComponent implements OnInit{
551552
552553
553554 insertPasteFile ( result : LoadResponse ) {
554- console . log ( "INSERTING " , result )
555555 this . processFileData ( result . data ) . then ( data => {
556+
557+ //after we have processed the data, we need to now relink any images that were duplicated in the process.
558+ let image_id_map = [ ] ;
559+ result . data . indexed_image_data . forEach ( image => {
560+ let media_item : IndexedColorImageInstance = this . media . duplicateIndexedColorImageInstance ( image . id ) ;
561+ image_id_map . push ( { from : image . id , to : media_item . id } )
562+ } )
563+
564+
565+ result . data . ops . forEach ( op => {
566+
567+ let op_base = this . ops . getOp ( op . name ) ;
568+ op_base . params . forEach ( ( param , ndx ) => {
569+
570+ if ( param . type == 'file' ) {
571+
572+ let from = op . params [ ndx ] ;
573+ let entry = image_id_map . find ( el => el . from == from ) ;
574+
575+ if ( entry !== undefined ) {
576+ let img_instance = < IndexedColorImageInstance > this . media . getMedia ( entry . to ) ;
577+ //this is just setting it locally, it needs to set the actual operation
578+ let op_node = this . tree . getOpNode ( op . node_id ) ;
579+ op_node . params [ ndx ] = { id : entry . to , data :img_instance . img } ;
580+
581+ }
582+ }
583+ } )
584+ } )
585+
586+
556587 this . saveFile ( ) ;
557588 }
558589 ) . catch ( console . error ) ;
@@ -670,7 +701,6 @@ export class AppComponent implements OnInit{
670701 loadNewFile ( result : LoadResponse , source : string ) : Promise < any > {
671702
672703
673- console . log ( "LOAD RESPONSE " , result )
674704
675705 return this . files . pushToLoadedFilesAndFocus ( result . id , result . name , result . desc )
676706 . then ( res => {
@@ -921,6 +951,7 @@ onPasteSelections(){
921951 this . upload_modal . afterClosed ( ) . subscribe ( loadResponse => {
922952 if ( loadResponse !== undefined && loadResponse != true )
923953 this . loadNewFile ( loadResponse , 'openFile' ) ;
954+ this . upload_modal = undefined ;
924955
925956 } ) ;
926957}
@@ -963,21 +994,39 @@ async processFileData(data: FileObj) : Promise<string|void>{
963994
964995 //1. filter any operations with a parameter of type file, and load the associated file.
965996 const images_to_load = [ ] ;
997+
998+ if ( data . filename !== 'paste' ) {
999+ //only load in new files if this is a true load event, if it is pasting from exisitng files, it doesn't need to re-analyze the images.
1000+ if ( utilInstance . sameOrNewerVersion ( data . version , '4.1.7' ) ) {
1001+ //LOAD THE NEW FILE OBJECT
1002+ data . indexed_image_data . forEach ( el => {
1003+ images_to_load . push ( { id : el . id , ref : el . ref , data :{ colors : el . colors , color_mapping : el . color_mapping } } ) ;
1004+ } )
1005+
1006+ } else {
1007+ console . log ( "LOADING OLDER VERSION " )
1008+ data . ops . forEach ( op => {
1009+ const internal_op = this . ops . getOp ( op . name ) ;
1010+ if ( internal_op === undefined || internal_op == null || internal_op . params === undefined ) return ;
1011+ const param_types = internal_op . params . map ( el => el . type ) ;
1012+ param_types . forEach ( ( p , ndx ) => {
1013+ //older version stored the media object reference in the parameter
1014+ if ( p == 'file' ) {
1015+ let new_id = utilInstance . generateId ( 8 ) ;
1016+ images_to_load . push ( { id : new_id , ref : op . params [ ndx ] , data :null } ) ;
1017+ op . params [ ndx ] = new_id ; //convert the value stored in memory to the instance id.
1018+ }
1019+ } ) ;
1020+ } )
1021+
1022+ }
1023+ }
9661024
967- data . ops . forEach ( op => {
968- const internal_op = this . ops . getOp ( op . name ) ;
969- if ( internal_op === undefined || internal_op == null || internal_op . params === undefined ) return ;
970- const param_types = internal_op . params . map ( el => el . type ) ;
971- param_types . forEach ( ( p , ndx ) => {
972- if ( p === 'file' ) {
973- images_to_load . push ( op . params [ ndx ] ) ;
974- }
975- } ) ;
976- } )
9771025
9781026
9791027
980- return this . image . loadFiles ( images_to_load ) . then ( el => {
1028+
1029+ return this . media . loadMedia ( images_to_load ) . then ( el => {
9811030 //2. check the op names, if any op names are old, relink the newer version of that operation. If not match is found, replaces with Rect.
9821031 return this . tree . replaceOutdatedOps ( data . ops ) ;
9831032 } )
0 commit comments