ConcernementMapItem.vue 131 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312
  1. <script>
  2. import REST from '@api/rest-axios'
  3. import { nextTick } from 'vue'
  4. import Matter from "matter-js";
  5. import MatterAttractors from "matter-attractors";
  6. // Matter.use(MatterAttractors);
  7. // import polydecomp from "poly-decomp";
  8. import paper from 'paper';
  9. // import { easeInOutQuad, easeInOutQuart } from 'easing-utils';
  10. import Tween from "@tweenjs/tween.js";
  11. import { mapState, mapActions } from 'pinia'
  12. import { ConcernementsStore } from '@/stores/concernements'
  13. import { CommonStore } from '@/stores/common'
  14. import { UserStore } from '@stores/user'
  15. // import { mdiPictureInPictureBottomRight } from '@mdi/js';
  16. export default {
  17. inject: ['canvasMap', 'matterEngine'],
  18. data() {
  19. return {
  20. id: null,
  21. cid: null,
  22. concernement: null,
  23. active_revision: null,
  24. entities: null,
  25. superposedEntiteID: null,
  26. // superposedEntitesIDsList: [],
  27. canvas: null,
  28. ctx: null,
  29. pos : {
  30. x: 0,
  31. y: 0
  32. },
  33. ray: 100,
  34. time: 0,
  35. salientPoints: [],
  36. scale: 1,
  37. prev_scale: 1,
  38. //
  39. entite_mouse_downed: null, // for entite dragging (admin front)
  40. wait: false,
  41. //
  42. details_zoom_scale: 1,
  43. is_dragging: false,
  44. //
  45. opacity: 0,
  46. tween: null,
  47. is_visible: true,
  48. is_open: false,
  49. is_opening: false,
  50. is_closing: false,
  51. is_hover: false,
  52. //
  53. body: null,
  54. body_parts: [],
  55. constraint: null,
  56. //
  57. paper_main_object: {},
  58. paper_groups: {},
  59. //
  60. doleance_transition: false,
  61. //
  62. paperContentsIsSet: false,
  63. }
  64. },
  65. props: ['mapitem'],
  66. computed: {
  67. ...mapState(ConcernementsStore,['map_mode',
  68. 'concernementsByID',
  69. 'allEntitesById',
  70. 'allSuperpositions_bycids',
  71. 'allSuperpositions_clustered',
  72. 'allMapItems_byid',
  73. 'opened_concernement',
  74. 'opened_entite_id',
  75. 'concernement_active_revision',
  76. 'detailsZoomValue',
  77. 'reloadConcernements',
  78. 'reloadConcernementEntites',
  79. 'concernements_loading_nb']),
  80. ...mapState(CommonStore,['hover_elmt',
  81. 'map_item_ray',
  82. 'cartouch_width',
  83. 'cartouch_is_opened',
  84. 'paper_symbol_definitions']),
  85. ...mapState(UserStore,['csrf_token']),
  86. },
  87. created () {
  88. console.log('ConcernementMapItem created', this.mapitem);
  89. // this.id = this.superposition_id ? `${this.cid}___${this.superposition_id}` : this.cid;
  90. // console.log(`this.mapitem.id`, this.mapitem.id);
  91. this.resetConcernement();
  92. // disable concernement if less than 3 entite
  93. if(this.entites.length < 3){
  94. this.hideShowConcernement(this.concernement.id, false);
  95. }
  96. // else{
  97. // record canvas and ctx for rendering (drawing)
  98. this.canvas = this.canvasMap.canvas
  99. this.ctx = this.canvasMap.ctx
  100. // define the ray regarding the width and height of screen
  101. this.ray = this.map_item_ray;
  102. // console.log(`this.ray: ${this.ray}`);
  103. //
  104. this.parseEntityPointsValues();
  105. // this.getSalientPoints()
  106. this.sailentEntites = this.concernement.sailentEntites = this.getJarvisEnvelopeConvexeEntites(this.entites)
  107. // define init position of the item
  108. this.pos = this.getRandomPos();
  109. //
  110. this.getSuperposedEntiteID();
  111. //
  112. this.initMatterBody()
  113. //
  114. this.initPaperObjects()
  115. //
  116. if(this.mapitem.clone){
  117. if(this.map_mode === 'superposition'){
  118. this.handleMapitemVisibility(true);
  119. }else{
  120. this.handleMapitemVisibility(false);
  121. }
  122. }
  123. // }
  124. // this.setConcernementMapItem(this.cid, this);
  125. // this.setConcernementScale(this.cid, this.scale);
  126. this.mapitem.scale = this.scale;
  127. // window.addEventListener('resize', this.onWindowResize.bind(this));
  128. },
  129. // mounted() {
  130. // console.log(`ConcernementsMapItem ${this.concernement.id} mounted`, this.canvasMap.canvas);
  131. // },
  132. // beforeUnmount () {
  133. unmounted () {
  134. // console.log(`mapitem ${this.id} unmounted`);
  135. if(this.mapitem.clone) {
  136. // console.log(`this.paper_main_object ${this.paper_main_object.id}`, this.paper_main_object);
  137. paper.project.getItem({id:this.paper_main_object.id}).remove();
  138. };
  139. if (this.body) {
  140. Matter.Composite.remove(this.matterEngine.world, this.body);
  141. }
  142. },
  143. watch: {
  144. canvasMap: {
  145. handler (n, o){
  146. // console.log("concernementItem watch canvasMap.ctx", typeof this.canvas, o, n);
  147. if (!this.canvas) {
  148. this.initCanvasMap()
  149. }
  150. },
  151. deep: true
  152. },
  153. opened_concernement: {
  154. handler (n, o) {
  155. // console.log(`concernementMapitem ${this.cid} watch opened_concernement o, n`, o, n);
  156. if (!n) { // if there is no opened concernement
  157. this.is_open = false;
  158. if (this.active_revision !== this.concernement.active_revision) {
  159. this.active_revision = this.concernement.active_revision;
  160. this.resetPaperEntitesAndContours();
  161. }
  162. this.applyShuffleForces();
  163. } else {
  164. if(this.cid === n.id && this.id === n.opened_mapitem_id){
  165. this.is_open = this.mapitem.is_open = true;
  166. }else{
  167. this.is_open = this.mapitem.is_open = false;
  168. }
  169. }
  170. },
  171. deep: true
  172. },
  173. is_open: {
  174. handler (n, o) {
  175. // console.log('mapItem watch is_open', n, this.is_open);
  176. if(n){ // opened
  177. this.openClose(true);
  178. }else if(o) { // closed if was opened
  179. this.openClose(false);
  180. }
  181. },
  182. deep: true
  183. },
  184. map_mode: {
  185. handler (n, o) {
  186. console.log('concernementMapItem watch map_mode', o, n);
  187. // apply a little force to check the map when returning to terrain de vie
  188. if (n === 'terraindevie' && !this.opened_concernement) {
  189. this.applyShuffleForces();
  190. }
  191. if (this.is_open && n !== "terraindevie"){
  192. console.log('concernementMapItem watch map_mode CALLING setDetailsZoomValue');
  193. this.setDetailsZoomValue(1);
  194. // we have to call updateDetailsZoomScale() right now, can't wait for wath f° which will append after the map_item contents redrawing
  195. this.updateDetailsZoomScale();
  196. }
  197. // if map_item is open and we change the mad mode, redefined what is displayed in the "boussole"
  198. if (this.is_open & n !== o) {
  199. this.resetPaperContents();
  200. this.resetMapItemPosition();
  201. this.resetMapItemScale();
  202. }
  203. // Clones visibility
  204. if(this.mapitem.clone){
  205. let is_visible = false;
  206. if(n === 'superposition'){
  207. // superposition mapemode all clones are visible
  208. is_visible = true;
  209. }else{
  210. if(this.opened_concernement){
  211. if(this.mapitem.is_open){
  212. is_visible = true;
  213. }else{
  214. // keep open the clones that are superposed to the opened map_item
  215. let opened_mapitem_id = this.opened_concernement.opened_mapitem_id;
  216. if (this.opened_concernement.superposed_mapitem_id_by_mapitem_id && this.opened_concernement.superposed_mapitem_id_by_mapitem_id[opened_mapitem_id]) {
  217. if(this.opened_concernement.superposed_mapitem_id_by_mapitem_id[opened_mapitem_id].indexOf(this.mapitem.id) !== -1){
  218. is_visible = true;
  219. }
  220. }
  221. }
  222. }
  223. }
  224. this.handleMapitemVisibility(is_visible);
  225. }
  226. },
  227. deep: true
  228. },
  229. hover_elmt: {
  230. handler (n, o) {
  231. // console.log(`watch hover_elmt ${this.id}`, o, n);
  232. if (n && (n.type === 'concernement' || n.type === 'superposition') && n.id === this.id) {
  233. this.is_hover = true;
  234. } else {
  235. this.is_hover = false;
  236. }
  237. },
  238. deep: true
  239. },
  240. is_hover: {
  241. handler (n, o) {
  242. this.onIsHover(n);
  243. },
  244. deep: true
  245. },
  246. concernement: {
  247. handler (n, o){
  248. console.log(`ConcernementMapItem ${this.id} watch concernement o, n`, this.concernement.parsedEntites, o, n);
  249. // check for active_revision changes
  250. // do not trigger on first variable filling (if o is null)
  251. // check for new concernement object
  252. if(!this.concernement.parsedEntites){
  253. console.log(`watch mapItem ${this.cid} reseting paperentitiesandcontours`);
  254. this.resetPaperEntitesAndContours();
  255. }
  256. // // check for new active_revision
  257. // // TODO fix that (it is loop triggering when new concernement object)
  258. // if(this.is_open && o && o.active_revision && n.active_revision && this.map_mode === "terraindevie"){
  259. // // be aware that here o & n active_revision are already the same :( !?
  260. // console.log(`concernementMapItem watch concernement o.active_revision:${o.active_revision}, n.active_revision:${n.active_revision}`);
  261. // // this.resetPaperEntitesAndContours();
  262. // }
  263. // // check for doleance change
  264. // if (this.is_open && o && o.opened_doleance && n.opened_doleance && this.map_mode === "doleancer") {
  265. // // be aware that here o & n opened_doleance are already the same :( !?
  266. // console.log(`concernementMapItem watch concernement o.opened_doleance:${o.opened_doleance.id}, n.opened_doleance:${n.opened_doleance.id}`);
  267. // }
  268. },
  269. deep: true
  270. },
  271. 'concernement.besoins': {
  272. handler (n, o){
  273. console.log(`ConcernementMapItem ${this.id} watch concernement.besoins o, n`, o, n);
  274. if (this.is_open && this.map_mode === "puissancedagir") {
  275. // this.resetPaperBesoinReponsePos();
  276. this.setPaperPuissanceagirBesoins(true); // true for update=true
  277. }
  278. },
  279. deep: true
  280. },
  281. 'concernement.besoins.length': {
  282. handler (n, o){
  283. console.log(`ConcernementMapItem ${this.id} watch concernement.besoins.length o, n`, o, n);
  284. if (this.is_open && this.map_mode === "puissancedagir" && o != null && n !== o) {
  285. this.resetPaperContents();
  286. }
  287. },
  288. deep: true
  289. },
  290. // window as been resized
  291. map_item_ray: {
  292. handler (n, o) {
  293. console.log(`map_item_ray updated o: ${o}, n: ${n}`);
  294. this.ray = n;
  295. this.updateMatterBodyRay();
  296. this.updatePaperObjectSize();
  297. },
  298. deep: true
  299. },
  300. concernement_active_revision: {
  301. handler (n, o){
  302. // console.log(`ConcernementMapItem ${this.id} watch concernement_active_revision o, n`, o, n);
  303. if (this.is_open && o) {
  304. // console.log(`n.cid: ${n.cid}, n.rid: ${n.rid}, this.is_open: ${this.is_open}, this.cid: ${this.cid}`);
  305. // console.log(this.cid, n.cid, n.rid);
  306. if (parseInt(n.cid) === this.cid) {
  307. this.active_revision = n.rid;
  308. this.resetPaperEntitesAndContours();
  309. }
  310. }
  311. },
  312. deep: true
  313. },
  314. detailsZoomValue: {
  315. handler (n, o) {
  316. if (this.is_open && this.map_mode === "terraindevie") {
  317. console.log('map_item detailsZoomValue watch', n);
  318. this.updateDetailsZoomScale()
  319. }
  320. },
  321. deep: true
  322. },
  323. // concernements_loading_nb: {
  324. // handler (n, o) {
  325. // console.log(`concernementMapItem ${this.id} watch concernements_loading_nb o, n`, o, n);
  326. // // this.resetPaperEntitesAndContours();
  327. // },
  328. // deep: true
  329. // },
  330. 'mapitem.concernements_loading_nb': {
  331. handler (n, o) {
  332. console.log(`ConcernementMapItem ${this.id} watch mapitem.concernements_loading_nb o, n`, o, n);
  333. // if (n.concernements_loading_nb !== o.concernements_loading_nb) {
  334. // this.resetPaperEntitesAndContours();
  335. // this.concernement = this.mapitem.concernement;
  336. this.resetConcernement();
  337. // }
  338. },
  339. deep: true
  340. },
  341. 'concernement.entites': {
  342. handler (n, o) {
  343. console.log(`ConcernementMapItem ${this.id} watch concernement.entites o, n`, o, n);
  344. // do not trigger on first fill of the property (if o is null)
  345. if (o) {
  346. this.resetPaperEntitesAndContours();
  347. this.resetPaperEntitesProximite();
  348. }
  349. },
  350. deep: true
  351. },
  352. wait: {
  353. handler (n, o){
  354. // when we are reloading entites par exemple
  355. // also handled by onMouseMove
  356. if (n) {
  357. document.body.style.cursor = "wait";
  358. } else {
  359. document.body.style.cursor = "auto";
  360. }
  361. }
  362. }
  363. },
  364. methods: {
  365. ...mapActions(CommonStore,['setHoverElmt']),
  366. ...mapActions(ConcernementsStore,['openCloseConcernements',
  367. 'hideShowConcernement',
  368. 'setOpenedEntiteId',
  369. 'setActiveRevision',
  370. 'setBesoinPaperId',
  371. 'setOpenedDoleanceField',
  372. 'setOpenedRecit',
  373. 'setDetailsZoomValue',
  374. ]),
  375. resetConcernement(){
  376. console.log(`resetConcernement() ${this.mapitem.id}`);
  377. this.id = this.mapitem.id;
  378. this.concernement = this.concernementsByID[this.mapitem.cid];// this.mapitem.concernement;
  379. this.cid = this.concernement.id;
  380. // console.log('mapitem this.cid', this.cid);
  381. this.active_revision = this.concernement.active_revision;
  382. // console.log(`ConcernementsMapItem ${this.id} created`);
  383. // this.entites = this.concernement.entites
  384. this.entites = this.concernement.revisions_byid[this.concernement.revision_id].entites;
  385. },
  386. parseEntityPointsValues (){
  387. console.log(`parseEntityPointsValues`);
  388. // converts data (menace/maintien, actuel/future, prise) into atcual position x,y
  389. for (let r = 0; r < this.concernement.revisions.length; r++) { // loop through all revisions
  390. for (let i = 0; i < this.concernement.revisions[r].entites.length; i++) { // loop through all entite for each revision
  391. let entite = this.concernement.revisions[r].entites[i]
  392. // console.log('entite', entite);
  393. entite.display = {
  394. alpha: null,
  395. ray: null
  396. }
  397. // RAYON
  398. // https://stackoverflow.com/questions/5731863/mapping-a-numeric-range-onto-another
  399. // slope = (output_end - output_start) / (input_end - input_start)
  400. // output = output_start + slope * (input - input_start)
  401. // from range 0 -> 100 to range 0 -> this.ray
  402. let init_max = 100
  403. let slope = this.ray / init_max
  404. entite.display.ray = slope * (init_max - entite.prise);
  405. // ANGLE
  406. // -90 <= mm <= 90
  407. if (entite.actuelfuture) {
  408. // future en haut : 180 <= a <= 360
  409. // from -90 -> 90 to range 180 -> 360
  410. entite.display.alpha = entite.menacemaintien + 270
  411. } else {
  412. // actuel: en bas : O <= a <= 180
  413. // from -90 -> 90 to range 180 -> 0
  414. entite.display.alpha = -1 * entite.menacemaintien + 90
  415. }
  416. // POSITION X Y (par rapport au centre du concernement)
  417. entite.display.pos = {
  418. x: entite.display.ray * Math.cos(entite.display.alpha * (Math.PI/180)),
  419. y: entite.display.ray * Math.sin(entite.display.alpha * (Math.PI/180))
  420. }
  421. // if (entite.entite) {
  422. // this.entites_byid[entite.entite.id].display = entite.display;
  423. // }
  424. }
  425. }
  426. this.concernement.parsedEntites = true;
  427. },
  428. getSalientPoints_OLD() {
  429. // debugger
  430. // console.log(this.entites);
  431. let arc = 360/30;
  432. // loop through arcs
  433. // for (let i = 360/arc; i >= 0 ; i--) {
  434. for (let i = 0; i <= 360/arc ; i++) {
  435. // loop through entities to find the farest on the arc
  436. let max_r = 0;
  437. let farest = null;
  438. for (let j = 0; j < this.entites.length; j++) {
  439. let entite = this.entites[j];
  440. if(arc*i <= entite.display.alpha && entite.display.alpha <= arc*i+arc) { // if entity is in arc
  441. if (entite.display.ray > max_r) { // && entite.display.ray > this.ray/2 // and farest from minimu
  442. // if entity is farest from precedent one
  443. max_r = entite.display.ray;
  444. // recalcul x & y to get a little padding between entite and contour by increasing ray
  445. farest = {
  446. alpha: entite.display.alpha,
  447. ray: entite.display.ray,
  448. pos: {
  449. x: (entite.display.ray + 3) * Math.cos(entite.display.alpha * (Math.PI/180)),
  450. y: (entite.display.ray + 3) * Math.sin(entite.display.alpha * (Math.PI/180))
  451. }
  452. };
  453. }
  454. }
  455. }
  456. if (farest) {
  457. this.salientPoints.push(farest)
  458. }
  459. }
  460. // console.log(`this.salientPoints ${this.concernement.id}`, this.salientPoints);
  461. },
  462. getJarvisEnvelopeConvexeEntites(entites){
  463. let sailentEntites = [];
  464. // https://www.geeksforgeeks.org/convex-hull-using-jarvis-algorithm-or-wrapping/
  465. // find the most left point
  466. let l, min_x = null;
  467. for (let i = 0; i < entites.length; i++) {
  468. let entite = entites[i];
  469. let x = entite.display.ray * Math.cos(entite.display.alpha * (Math.PI/180));
  470. if(!min_x || min_x > x){
  471. l = i;
  472. min_x = x;
  473. }
  474. }
  475. // Start from leftmost point, keep moving clockwise
  476. // until reach the start point again. This loop runs O(h)
  477. // times where h is number of points in result or output.
  478. let p = l, q;
  479. do {
  480. // console.log(`do while ${this.id}`, p);
  481. // Add current point to result
  482. let entite = entites[p];
  483. sailentEntites.push(entite);
  484. // Search for a point 'q' such that
  485. // orientation(p, q, x) is clockwise
  486. // for all points 'x'. The idea is to keep
  487. // track of last visited most clockwise
  488. // point in q. If any point 'i' is more
  489. // clockwise than q, then update q.
  490. q = (p + 1) % entites.length;
  491. for (let i = 0; i < entites.length; i++) {
  492. let p_x = (entites[p].display.ray) * Math.cos(entites[p].display.alpha * (Math.PI/180));
  493. let p_y = (entites[p].display.ray) * Math.sin(entites[p].display.alpha * (Math.PI/180));
  494. let i_x = (entites[i].display.ray) * Math.cos(entites[i].display.alpha * (Math.PI/180));
  495. let i_y = (entites[i].display.ray) * Math.sin(entites[i].display.alpha * (Math.PI/180));
  496. let q_x = (entites[q].display.ray) * Math.cos(entites[q].display.alpha * (Math.PI/180));
  497. let q_y = (entites[q].display.ray) * Math.sin(entites[q].display.alpha * (Math.PI/180));
  498. let val = (i_y - p_y) * (q_x - i_x) - (i_x - p_x) * (q_y - i_y);
  499. // If i is more clockwise than current q, then update q
  500. if (val > 0){
  501. q = i;
  502. }
  503. }
  504. // Now q is the most clockwise with
  505. // respect to p. Set p as q for next iteration,
  506. // so that q is added to result 'hull'
  507. p = q;
  508. } while (p != l);
  509. return sailentEntites;
  510. },
  511. getRandomPos(){
  512. let pad = 200;
  513. // if (this.concernement.id === 56) {
  514. // return {
  515. // x: Math.random() > 0.5 ? pad : this.canvas.width - pad,
  516. // y: pad + this.ray/2 + Math.random()*(this.canvas.height - this.ray - pad)
  517. // };
  518. // } else {
  519. return {
  520. x: pad + this.getGaussianRandom()*(this.canvas.width - pad*2),
  521. y: pad + this.getGaussianRandom()*(this.canvas.height - pad*2)
  522. };
  523. // }
  524. },
  525. getGaussianRandom(){
  526. // INFO https://stackoverflow.com/a/49434653
  527. let u = 0, v = 0;
  528. while(u === 0) u = Math.random(); //Converting [0,1) to (0,1)
  529. while(v === 0) v = Math.random();
  530. let num = Math.sqrt( -2.0 * Math.log( u ) ) * Math.cos( 2.0 * Math.PI * v );
  531. num = num / 10.0 + 0.5; // Translate to 0 -> 1
  532. if (num > 1 || num < 0) return this.getGaussianRandom() // resample between 0 and 1
  533. return num
  534. },
  535. getSuperposedEntiteID(){
  536. if (this.concernement.has_superpositions) {
  537. let ids = this.id.match(/(\d+)___(\d+)/i);
  538. if (ids) {
  539. let cluster_index = ids[2];
  540. // console.log(ids, cluster_index);
  541. for(let cid_eid of this.allSuperpositions_clustered[cluster_index] ){
  542. if(this.cid === cid_eid.cid){
  543. this.superposedEntiteID = cid_eid.eid;
  544. break;
  545. }
  546. }
  547. }
  548. }
  549. },
  550. // MATTER BODY
  551. initMatterBody (){
  552. // MATTER
  553. // create the matter body and add it to the engine
  554. if (!this.body) {
  555. // console.log('concernementItem creating body');
  556. // INFO https://github.com/liabru/matter-attractors/issues/8
  557. // INFO https://github.com/liabru/matter-attractors/blob/master/index.js
  558. // INFO https://github.com/liabru/matter-attractors/blob/master/build/matter-attractors.js#L180
  559. MatterAttractors.Attractors.gravityConstant = -20;
  560. // Create parts of the body : main big circle & entities
  561. // INFO map a range of numbers to another range of numbers https://stackoverflow.com/a/46462321
  562. let entite_range = [3, 100];
  563. let ray_range = [this.ray*0.8,this.ray*1.2];
  564. let ray = ray_range[0] + (this.entites.length - entite_range[0]) * (ray_range[1] - ray_range[0]) / (entite_range[1] - entite_range[0]);
  565. // this.body_parts = [
  566. // Matter.Bodies.circle(0, 0, ray)
  567. // ];
  568. // INFO map a range of numbers to another range of numbers https://stackoverflow.com/a/46462321
  569. let mass_range = [5,15];
  570. let mass = mass_range[0] + (this.entites.length - entite_range[0]) * (mass_range[1] - mass_range[0]) / (entite_range[1] - entite_range[0]);
  571. // create the body
  572. this.body = Matter.Bodies.circle(0, 0, ray, {
  573. item_type: 'concernement',
  574. id: this.id,
  575. frictionAir: 0,
  576. mass: mass,
  577. restitution: 0.06,
  578. collisionFilter: {
  579. group: -1,
  580. category: 0x0002,
  581. mask: 0x0001
  582. },
  583. plugin: {
  584. attractors: [
  585. // // there is a built in helper function for Newtonian gravity!
  586. // // you can find out how it works in index.js
  587. MatterAttractors.Attractors.gravity
  588. // function(bodyA, bodyB) {
  589. // var force = {
  590. // x: (bodyA.position.x - bodyB.position.x) * 1e-6,
  591. // y: (bodyA.position.y - bodyB.position.y) * 1e-6
  592. // }
  593. // // apply force to both bodies
  594. // Matter.Body.applyForce(bodyA, bodyA.position, force);
  595. // Matter.Body.applyForce(bodyB, bodyB.position, Matter.Vector.neg(force));
  596. // }
  597. // INFO https://github.com/liabru/matter-attractors/blob/master/build/matter-attractors.js#L192
  598. // function (bodyA, bodyB){
  599. // // use Newton's law of gravitation
  600. // var bToA = Matter.Vector.sub(bodyB.position, bodyA.position),
  601. // distanceSq = Matter.Vector.magnitudeSquared(bToA) || 0.0001,
  602. // normal = Matter.Vector.normalise(bToA),
  603. // magnitude = -MatterAttractors.Attractors.gravityConstant * (bodyA.mass * bodyB.mass / distanceSq),
  604. // force = Matter.Vector.mult(normal, magnitude);
  605. // // to apply forces to both bodies
  606. // Matter.Body.applyForce(bodyA, bodyA.position, Matter.Vector.neg(force));
  607. // Matter.Body.applyForce(bodyB, bodyB.position, force);
  608. // }
  609. ]
  610. }
  611. })
  612. // this.body = Matter.Body.create({
  613. // parts: this.body_parts,
  614. // item_type: 'concernement',
  615. // id: this.id,
  616. // frictionAir: 0,
  617. // // mass: Math.pow(3, this.entites.length),
  618. // // mass: 10,
  619. // mass: mass,
  620. // restitution: 0.06,
  621. // collisionFilter: {
  622. // group: -1
  623. // },
  624. // plugin: {
  625. // attractors: [
  626. // // // there is a built in helper function for Newtonian gravity!
  627. // // // you can find out how it works in index.js
  628. // MatterAttractors.Attractors.gravity
  629. // // function(bodyA, bodyB) {
  630. // // var force = {
  631. // // x: (bodyA.position.x - bodyB.position.x) * 1e-6,
  632. // // y: (bodyA.position.y - bodyB.position.y) * 1e-6
  633. // // }
  634. // // // apply force to both bodies
  635. // // Matter.Body.applyForce(bodyA, bodyA.position, force);
  636. // // Matter.Body.applyForce(bodyB, bodyB.position, Matter.Vector.neg(force));
  637. // // }
  638. // // INFO https://github.com/liabru/matter-attractors/blob/master/build/matter-attractors.js#L192
  639. // // function (bodyA, bodyB){
  640. // // // use Newton's law of gravitation
  641. // // var bToA = Matter.Vector.sub(bodyB.position, bodyA.position),
  642. // // distanceSq = Matter.Vector.magnitudeSquared(bToA) || 0.0001,
  643. // // normal = Matter.Vector.normalise(bToA),
  644. // // magnitude = -MatterAttractors.Attractors.gravityConstant * (bodyA.mass * bodyB.mass / distanceSq),
  645. // // force = Matter.Vector.mult(normal, magnitude);
  646. // // // to apply forces to both bodies
  647. // // Matter.Body.applyForce(bodyA, bodyA.position, Matter.Vector.neg(force));
  648. // // Matter.Body.applyForce(bodyB, bodyB.position, force);
  649. // // }
  650. // ]
  651. // }
  652. // });
  653. Matter.Body.setPosition(this.body, this.pos);
  654. // add init velocity
  655. // INFO no need of init velocity as each mapitems are repeling the each others
  656. // this.setInitBodyVelocity()
  657. // console.log('concernementItem mass', this.body.mass);
  658. Matter.Composite.add(this.matterEngine.world, this.body);
  659. // console.log('concernement body', this.body);
  660. // listen for afterUpdate event from Matter.Engine object
  661. Matter.Events.on(this.matterEngine, "beforeUpdate", this.onBeforeEngineUpdate);
  662. Matter.Events.on(this.matterEngine, "afterUpdate", this.onAfterEngineUpdate);
  663. }
  664. },
  665. setInitBodyVelocity(){
  666. let delta = 5;
  667. Matter.Body.setVelocity(this.body, {
  668. x: -delta + Math.random()*delta*2,
  669. y: -delta + Math.random()*delta*2
  670. });
  671. },
  672. updateMatterBodyRay(){
  673. console.log('updateMatterBodyRay',this.ray, this.body);
  674. let entite_range = [3, 100];
  675. let ray_range = [this.ray*0.8,this.ray*1.2];
  676. let new_ray = ray_range[0] + (this.entites.length - entite_range[0]) * (ray_range[1] - ray_range[0]) / (entite_range[1] - entite_range[0]);
  677. let old_ray = this.body.circleRadius;
  678. let scale = new_ray/old_ray;
  679. Matter.Body.scale(this.body, scale, scale);
  680. // Matter.Body.set(this.body, 'circleRadius', ray);
  681. console.log(`this.body circleRadius ${this.body.circleRadius}`);
  682. },
  683. // PAPER OBJECTS
  684. initPaperObjects(){
  685. // the main paper group containing all paper graphical items for one concernement
  686. this.paper_main_object = new paper.Group({
  687. pivot: new paper.Point(this.pos),
  688. name: `main_${this.id}`,
  689. cid: this.cid,
  690. // superposition_id: this.mapitem.superposition_ids[0]
  691. });
  692. // fadein intro
  693. // if(!this.mapitem.clone){
  694. this.paper_main_object.opacity = (1 + Math.random())*0.001;
  695. // }
  696. // the sub items for one concernement
  697. this.paper_main_object.addChild(this.setPaperContour());
  698. if (this.concernement.has_superpositions) {
  699. this.paper_main_object.addChild(this.setPaperEntitesSuperposees());
  700. }
  701. if (this.concernement.has_proximites) {
  702. this.paper_main_object.addChild(this.setPaperEntitesProximite());
  703. }
  704. // if (this.concernement.has_puissancedagir) {
  705. // this.addNewPaperSymbolInstance('puissanceagir_icon', false, 0.7);
  706. // }
  707. // if (this.concernement.has_agissantes) {
  708. // this.paper_main_object.addChild(this.setPaperAgissantesIcons());
  709. // }
  710. // if (this.concernement.has_doleance) {
  711. // this.addNewPaperSymbolInstance('doleance_icon', false, 0.7);
  712. // }
  713. this.initPaperEvents()
  714. },
  715. async updatePaperObjectSize(){
  716. await nextTick();
  717. // INFO we redraw the points with the new ray AND sacle the backgrounds ... would it be simplier to only resize the whole mapitem ???
  718. // window has been resized
  719. // if open
  720. if (this.is_open) {
  721. // move to the new position
  722. // INFO we need to change position first for the contours to be redraw in the right place
  723. // this.resetMapItemPosition();
  724. this.pos = this.paper_main_object.position = {
  725. x: (this.canvas.width - this.cartouch_width) / 2,
  726. y: this.canvas.height / 2
  727. };
  728. this.constraint.pointA = this.pos;
  729. Matter.Body.setPosition(this.body, this.pos);
  730. // reset the paper contents with paper symbols redrew by MapConcernements.vue
  731. this.setPaperContents();
  732. // scale
  733. // let s = this.getOpeningAvailableScale();
  734. // this.paper_main_object.scale(1 / this.scale);
  735. // this.paper_main_object.scale(s);
  736. }
  737. // in any case
  738. // delet the old contours
  739. let clearables = ['contours'];
  740. clearables.forEach(child_name => {
  741. if (this.paper_main_object.children[child_name]) {
  742. this.paper_main_object.children[child_name].remove();
  743. }
  744. });
  745. // rebuild the contours with the new ray
  746. this.parseEntityPointsValues()
  747. this.sailentEntites = this.concernement.sailentEntites = this.getJarvisEnvelopeConvexeEntites(this.entites)
  748. // redraw the contours
  749. this.paper_main_object.addChild(this.setPaperContour());
  750. },
  751. updateDetailsZoomScale(){
  752. console.log(`updateDetailsZoomScale ${this.detailsZoomValue}`);
  753. // revert to the original size (by reverting the previous scale)
  754. this.paper_main_object.scale(1 / this.details_zoom_scale);
  755. // compute intial entite scale before computing new details_zoom_scale
  756. let prev_entite_s = 1 / this.details_zoom_scale;
  757. // compute the zoom scale
  758. this.details_zoom_scale = this.scale * this.detailsZoomValue;
  759. // then scale again to new size
  760. this.paper_main_object.scale(this.details_zoom_scale);
  761. // resize entites (dim them while we zoomin)
  762. if(this.paper_main_object.children && this.paper_main_object.children['entites']){
  763. this.paper_main_object.children['entites'].children.forEach((child) => {
  764. if(child.name === 'entite'){
  765. // revert to the original size (by reverting the previous scale)
  766. child.scale(1 / prev_entite_s);
  767. // then scale again to new size
  768. child.scale(1 / this.details_zoom_scale);
  769. }else if(child.name === 'entites_labels'){
  770. child.opacity = -2 + this.detailsZoomValue;
  771. child.children.forEach((label) => {
  772. // revert to the original size (by reverting the previous scale)
  773. label.scale(1 / prev_entite_s);
  774. // then scale again to new size
  775. label.scale(1 / this.details_zoom_scale);
  776. // label.children['label_txt'].fontSize = 4 / this.detailsZoomValue;
  777. })
  778. }
  779. });
  780. }
  781. // allow to go through walls if zoomed in
  782. if (this.detailsZoomValue > 1) {
  783. this.body.collisionFilter.mask = 0x0004;
  784. } else {
  785. this.body.collisionFilter.mask = 0x0001;
  786. this.resetMapItemPosition();
  787. }
  788. },
  789. /*
  790. * called by openClose() function
  791. */
  792. setPaperContents(){
  793. console.log('setPaperContents');
  794. // trigered once opening tween is complete
  795. // trigered once mapmode changed
  796. // triggerd when reseting papercontents
  797. if (!this.paperContentsIsSet) {
  798. this.clearPaperContents();
  799. switch(this.map_mode){
  800. case 'terraindevie':
  801. this.addNewPaperSymbolInstance('boussole_bg', true);
  802. this.paper_main_object.addChild(this.setPaperEntites());
  803. // this.setPaperEntitesEvents();
  804. break;
  805. case 'superposition':
  806. this.addNewPaperSymbolInstance('boussole_bg', true);
  807. break;
  808. case 'proximite':
  809. this.addNewPaperSymbolInstance('boussole_bg', true);
  810. this.paper_main_object.addChild(this.setPaperEntitesProximiteReferences());
  811. break;
  812. case 'puissancedagir':
  813. this.addNewPaperSymbolInstance('puissanceagir_bg', true);
  814. this.paper_main_object.addChild(this.setPaperPuissanceagirBesoins());
  815. break;
  816. case 'action':
  817. this.addNewPaperSymbolInstance('boussole_bg', true);
  818. this.paper_main_object.addChild(this.setPaperAgissantes());
  819. break;
  820. case 'doleancer':
  821. this.addNewPaperSymbolInstance('doleance_bg');
  822. this.paper_main_object.addChild(this.setPaperDoleances());
  823. break;
  824. }
  825. this.paperContentsIsSet = true;
  826. }
  827. },
  828. resetPaperContents(){
  829. this.paperContentsIsSet = false;
  830. this.setPaperContents();
  831. },
  832. resetPaperEntitesAndContours(){
  833. console.log(`concernementMapitem ${this.id} resetPaperEntitesAndContours this.concernement`, this.concernement);
  834. if (!this.isResetingPaperEntites) {
  835. console.log(`ResetingPaperEntites ${this.id}`);
  836. this.isResetingPaperEntites = true;
  837. this.active_revision = this.concernement.active_revision;
  838. console.log(`this.active_revision ${this.active_revision}`);
  839. console.log(`entite len : ${this.concernement.revisions_byid[this.active_revision].entites.length}`);
  840. this.parseEntityPointsValues()
  841. this.sailentEntites = this.getJarvisEnvelopeConvexeEntites(this.concernement.revisions_byid[this.active_revision].entites);
  842. // remove contours if already exists
  843. if (this.paper_main_object.children && this.paper_main_object.children.contours) {
  844. this.paper_main_object.children.contours.remove();
  845. }
  846. // redraw contours
  847. this.paper_main_object.addChild(this.setPaperContour());
  848. // remove entites if already exists
  849. if (this.paper_main_object.children.entites) {
  850. this.paper_main_object.children.entites.remove();
  851. }
  852. // redraw entites
  853. this.paper_main_object.addChild(this.setPaperEntites());
  854. this.isResetingPaperEntites = false;
  855. console.log(`END ResetingPaperEntites ${this.id}`);
  856. }
  857. },
  858. clearPaperContents(){
  859. let clearable_children = ['boussole_bg', 'entites',
  860. 'entites_proximites_references',
  861. 'puissanceagir_bg','puissanceagir_besoins',
  862. 'agissantes',
  863. 'doleance_bg', 'doleances'];
  864. clearable_children.forEach(child_name => {
  865. if (this.paper_main_object.children[child_name]) {
  866. this.paper_main_object.children[child_name].remove();
  867. }
  868. });
  869. this.paperContentsIsSet = false;
  870. },
  871. addNewPaperSymbolInstance(name, back, scale){
  872. let instance = new paper.SymbolItem(this.paper_symbol_definitions[name]); // , {x:0,y:0}
  873. instance.name = name;
  874. instance.position = this.pos;
  875. let s = scale ? this.scale * scale : this.scale;
  876. instance.scale(s);
  877. // instance.locked = true;
  878. this.paper_main_object.addChild(instance);
  879. if (back) {
  880. this.paper_main_object.children[name].sendToBack();
  881. } else {
  882. this.paper_main_object.children[name].bringToFront();
  883. }
  884. },
  885. getPaddedRoundedSegments(points, scale){
  886. console.log(`setPaperContour ${this.concernement.id}, points`, points);
  887. let getSegmentProps = (b,a,c) => {
  888. const ac = { x: c.x - a.x, y: c.y - a.y } // get ac vecteur
  889. const lac = Math.sqrt(Math.pow(ac.x, 2) + Math.pow(ac.y, 2)); // get ac longueur ac
  890. const ab = { x: b.x - a.x, y: b.y - a.y } // get ab vecteur
  891. const lab = Math.sqrt(Math.pow(ab.x, 2) + Math.pow(ab.y, 2)); // get ab longeur
  892. const vab = { x: ab.x/lab, y: ab.y/lab } // get unit vecteur ab
  893. const an = { x: vab.x*lac, y: vab.y*lac } // get an vecteur
  894. const n = { x: a.x + an.x, y: a.y+an.y } // get n point
  895. const m = { x: (c.x + n.x)/2, y: (c.y + n.y)/2 } // get nc midle point
  896. const ma = { x:a.x - m.x, y: a.y - m.y } // get ma vecteur
  897. const lma = Math.sqrt(Math.pow(ma.x, 2)+Math.pow(ma.y, 2)) // get longeur m->a
  898. const vma = { x: ma.x/lma, y: ma.y/lma } // get ma vecteur unitaire
  899. // console.log(`vma x:${vma.x}, y:${vma.y}`);
  900. const pad = 4; // exterior padding
  901. // the final padded point
  902. const pa = [
  903. a.x+vma.x*pad,
  904. a.y+vma.y*pad
  905. ]
  906. // handles
  907. const delta = 0.05 * scale;
  908. // handle IN
  909. const hli = Math.abs(lab)*delta; // handle longeur
  910. const vnai = { x: -vma.y, y: vma.x } // get the ma normal unit vector IN
  911. const hai = [ vnai.x*hli, vnai.y*hli ]; // get the handleIn point
  912. // handle OUT
  913. const hlo = Math.abs(lac)*delta; // handle longeur
  914. const vnao = { x: vma.y, y: -vma.x } // get the ma normal vector Out
  915. const hao = [ vnao.x*hlo, vnao.y*hlo ]; // get the handleOut point
  916. return {
  917. point: pa,
  918. handleIn: hai,
  919. handleOut: hao
  920. }
  921. }
  922. const first_point = getSegmentProps(
  923. points[points.length-1],
  924. points[0],
  925. points[1]
  926. );
  927. let segments = [first_point];
  928. for (let j = 1; j < points.length-1; j++) {
  929. segments.push(getSegmentProps(
  930. points[j-1],
  931. points[j],
  932. points[j+1]
  933. ))
  934. }
  935. const last_point = getSegmentProps(
  936. points[points.length-2],
  937. points[points.length-1],
  938. points[0]
  939. );
  940. segments.push(last_point)
  941. segments.push(first_point)
  942. return segments;
  943. },
  944. setPaperContour(){
  945. // console.log('setPaperContour, this.sailentEntites', this.sailentEntites);
  946. // convert sailent entites to x,y points
  947. if (this.sailentEntites.length < 3) {
  948. // if we have less than 3 entities, draw a circle
  949. let circle = new paper.Path.Circle({
  950. name: 'contours',
  951. center: this.pos,
  952. radius: this.ray/3,
  953. fillColor: 'rgba(255,255,255,0.4)',
  954. // selected: true,
  955. strokeColor: '#fff',
  956. strokeWidth: 1,
  957. pivot: new paper.Point(this.pos),
  958. // scale: this.details_zoom_scale,
  959. cid: this.cid,
  960. })
  961. return circle;
  962. } else {
  963. // if we have more than 3 entities, draw normal contour
  964. let points = [];
  965. this.sailentEntites.forEach(entite => {
  966. points.push({
  967. x: (entite.display.ray) * Math.cos(entite.display.alpha * (Math.PI/180)),
  968. y: (entite.display.ray) * Math.sin(entite.display.alpha * (Math.PI/180))
  969. })
  970. })
  971. // convert points to rouded and padded segments props
  972. let segments = this.getPaddedRoundedSegments(points, this.scale)
  973. // create "real" Paper Segments from previous segments props
  974. let paper_segments = [];
  975. segments.forEach(seg => {
  976. paper_segments.push(new paper.Segment({
  977. point: [this.pos.x+seg.point[0]*this.details_zoom_scale, this.pos.y+seg.point[1]*this.details_zoom_scale],
  978. handleIn: seg.handleIn,
  979. handleout: seg.handleOut
  980. }))
  981. });
  982. // create the paper path with previous segments
  983. let contrs = new paper.Path({
  984. name: 'contours',
  985. segments: paper_segments,
  986. fillColor: 'rgba(255,255,255,0.4)',
  987. // selected: true,
  988. strokeColor: '#fff',
  989. strokeWidth: 1,
  990. pivot: new paper.Point(this.pos),
  991. // scale: this.details_zoom_scale,
  992. cid: this.cid,
  993. });
  994. // return the paper path
  995. return contrs;
  996. }
  997. },
  998. setPaperEntites(){
  999. let g = new paper.Group({
  1000. pivot: new paper.Point(this.pos),
  1001. name: 'entites'
  1002. });
  1003. let g_label = new paper.Group({
  1004. pivot: new paper.Point(this.pos),
  1005. name: 'entites_labels',
  1006. opacity: 0
  1007. });
  1008. g.addChild(g_label);
  1009. g_label.sendToBack();
  1010. // for (let i = 0; i < this.entites.length; i++) {
  1011. for (let i = 0; i < this.concernement.revisions_byid[this.active_revision].entites.length; i++) {
  1012. let entite = this.concernement.revisions_byid[this.active_revision].entites[i];
  1013. // item type
  1014. let item_type = entite.entite ? entite.entite.agissante ? 'entite_action' : 'entite' : 'entite_hidden';
  1015. // use paper symbol
  1016. let symbol_name = item_type;
  1017. switch (item_type) {
  1018. case 'entite':
  1019. if(parseInt(this.opened_entite_id) === entite.entite.id){
  1020. symbol_name = 'entite_hover';
  1021. }
  1022. break;
  1023. case 'entite_action':
  1024. if(parseInt(this.opened_entite_id) === entite.entite.id){
  1025. symbol_name = 'entite_action_hover';
  1026. }
  1027. break;
  1028. }
  1029. // console.log(`item_type: ${item_type}, symbol_name: ${symbol_name}`);
  1030. let instance = new paper.SymbolItem(this.paper_symbol_definitions[symbol_name]);
  1031. instance.name = 'entite';
  1032. let pos_point = new paper.Point([this.pos.x + entite.display.pos.x * this.details_zoom_scale, this.pos.y + entite.display.pos.y * this.details_zoom_scale]);
  1033. instance.position = pos_point;
  1034. instance.scale(this.scale);
  1035. instance.fillColor = '#000';
  1036. instance.item_id = entite.entite ? entite.entite.id : null;
  1037. instance.item_type = item_type;
  1038. instance.is_symbol_instance = true;
  1039. g.addChild(instance);
  1040. // instance.bringToFront();
  1041. if (entite.entite && entite.entite.title) {
  1042. let pad = 2;
  1043. let label_pos = new paper.Point({
  1044. x: pos_point.x + pad,
  1045. y: pos_point.y - pad*2
  1046. });
  1047. let label = new paper.Group({
  1048. pivot: pos_point,
  1049. name: 'label',
  1050. item_id: entite.entite ? entite.entite.id : null,
  1051. item_type: item_type
  1052. });
  1053. let title = entite.entite.title;
  1054. title = (title.length > 25) ? title.slice(0, 25 - 1) + '…' : title;
  1055. let label_txt = new paper.PointText({
  1056. pivot: pos_point,
  1057. point: label_pos,
  1058. content: title,
  1059. fillColor: 'black',
  1060. fontFamily: 'public_sans',
  1061. fontSize: 3,
  1062. justification: 'left',
  1063. name: 'label_txt'
  1064. })
  1065. let b = label_txt.bounds;
  1066. let rect = new paper.Rectangle(b.x - pad, b.y - pad, b.width + pad*2, b.height + pad*2);
  1067. let corners = new paper.Size(1,1);
  1068. let label_bg = new paper.Path.Rectangle(rect, corners);
  1069. label_bg.fillColor = '#fff';
  1070. label_bg.strokeColor = '#fff';
  1071. label_bg.strokeWidth = 1;
  1072. label_bg.opacity = 0.9;
  1073. label_bg.name = 'label_bg';
  1074. let label_click_zone = new paper.Path.Rectangle(b.x - pad, b.y - pad, b.width + pad*2, b.height + pad*2);
  1075. label_click_zone.fillColor = '#fff';
  1076. label_click_zone.opacity = 0;
  1077. label_click_zone.name = 'label_click_zone';
  1078. label_click_zone.item_id = entite.entite ? entite.entite.id : null;
  1079. label_click_zone.item_type = item_type;
  1080. label.addChild(label_bg);
  1081. label_txt.insertAbove(label_bg);
  1082. label_click_zone.insertAbove(label_txt);
  1083. // label.sendToBack();
  1084. g_label.addChild(label);
  1085. instance.label_item = label;
  1086. }
  1087. }
  1088. return g;
  1089. },
  1090. setPaperEntitesSuperposees(){
  1091. // console.log('setPaperSuperpositions, superpositions', this.concernement.superpositions);
  1092. let g = new paper.Group({
  1093. pivot: new paper.Point(this.pos),
  1094. name: 'entites_superposes'
  1095. });
  1096. for (let i = 0; i < this.concernement.revisions_byid[this.active_revision].entites.length; i++) {
  1097. let entite = this.concernement.revisions_byid[this.active_revision].entites[i];
  1098. if (entite.entite // check if we have an entite object with all the contents
  1099. && this.superposedEntiteID === entite.entite.id) // check if entite id
  1100. {
  1101. // console.log(`entite ${entite.entite.id}`, entite, entite.entite.superposition);
  1102. // use paper symbol
  1103. let instance = new paper.SymbolItem(this.paper_symbol_definitions['entite']);
  1104. instance.name = 'entite';
  1105. instance.position = new paper.Point([this.pos.x + entite.display.pos.x * this.scale, this.pos.y + entite.display.pos.y * this.scale]);
  1106. // instance.scale(this.scale);
  1107. instance.scale(3);
  1108. instance.fillColor = '#000';
  1109. instance.item_id = entite.entite.id;
  1110. instance.item_type = 'entite_superpose';
  1111. instance.is_symbol_instance = true;
  1112. g.addChild(instance)
  1113. break; // there is only one superposed entite by mapitem
  1114. }
  1115. }
  1116. return g;
  1117. },
  1118. setPaperEntitesProximite(){
  1119. let g = new paper.Group({
  1120. pivot: new paper.Point(this.pos),
  1121. name: 'entites_proximites'
  1122. });
  1123. for (let i = 0; i < this.concernement.revisions_byid[this.active_revision].entites.length; i++) {
  1124. let entite = this.concernement.revisions_byid[this.active_revision].entites[i];
  1125. if (entite.entite // check if we have an entite object with all the contents
  1126. && entite.entite.proximite.length ) // check if entite id is in the list builded above
  1127. {
  1128. // console.log(`entite ${entite.entite.id}`, entite, entite.entite.superposition);
  1129. // use paper symbol
  1130. let instance = new paper.SymbolItem(this.paper_symbol_definitions['entite']);
  1131. instance.name = 'entite';
  1132. instance.position = new paper.Point([this.pos.x + entite.display.pos.x * this.scale, this.pos.y + entite.display.pos.y * this.scale]);
  1133. // instance.scale(this.scale);
  1134. instance.scale(3);
  1135. instance.fillColor = '#000';
  1136. instance.item_id = entite.entite.id;
  1137. instance.item_type = 'entite_proximite';
  1138. instance.is_symbol_instance = true;
  1139. g.addChild(instance)
  1140. }
  1141. }
  1142. return g;
  1143. },
  1144. resetPaperEntitesProximite(){
  1145. if (this.paper_main_object.children['entites_proximites']) {
  1146. this.paper_main_object.children['entites_proximites'].remove();
  1147. }
  1148. if (this.concernement.has_proximites) {
  1149. this.paper_main_object.addChild(this.setPaperEntitesProximite());
  1150. }
  1151. },
  1152. setPaperEntitesProximiteReferences(){
  1153. console.log('setPaperEntitesProximiteReferences')
  1154. let g = new paper.Group({
  1155. pivot: new paper.Point(this.pos),
  1156. name: 'entites_proximites_references'
  1157. });
  1158. // loop through all concernement's entites
  1159. // keeping only those who have proximite
  1160. for (let i = 0; i < this.concernement.revisions_byid[this.active_revision].entites.length; i++) {
  1161. let entite = this.concernement.revisions_byid[this.active_revision].entites[i];
  1162. if (entite.entite // check if we have an entite object with all the contents
  1163. && entite.entite.proximite.length ) // check if entite id is in the list builded above
  1164. {
  1165. // console.log(`PROXIMITE entite ${entite.entite.id}`, entite, entite.entite.proximite);
  1166. // create the main entite paper point object
  1167. let entite_pos = {
  1168. x: this.pos.x + entite.display.pos.x * this.scale,
  1169. y: this.pos.y + entite.display.pos.y * this.scale
  1170. }
  1171. // console.log(`entite_pos x:${entite_pos.x}, y:${entite_pos.y}`);
  1172. // use paper symbol
  1173. let instance = new paper.SymbolItem(this.paper_symbol_definitions['entite']);
  1174. instance.name = 'entite';
  1175. instance.position = new paper.Point([entite_pos.x, entite_pos.y]);
  1176. // instance.scale(this.scale);
  1177. instance.scale(this.scale);
  1178. instance.fillColor = '#000';
  1179. instance.item_id = entite.entite.id;
  1180. instance.item_type = 'entite_proximite';
  1181. instance.is_symbol_instance = true;
  1182. g.addChild(instance)
  1183. // create the proximite reference of the main entite
  1184. // a paper group wich contains the ref entite point and the ref concernement's contour
  1185. let ref_g = new paper.Group({
  1186. pivot: new paper.Point(this.pos),
  1187. name: 'ref_entite_proximite'
  1188. });
  1189. let allEntiteRefConcernementContourEntites = [];
  1190. let beta = 360 / entite.entite.proximite.length;
  1191. let ray = 5;
  1192. let e=0;
  1193. // define the right scaling down of the big original concernement contours
  1194. let scaledown = 0.05;
  1195. entite.entite.proximite.forEach(entite_ref => {
  1196. // console.log(`${entite_ref.id}, ${entite_ref.title}`, this.allEntitesById[entite_ref.id]);
  1197. // get the concernement parents of the proximite reference
  1198. let ref_cid = this.allEntitesById[entite_ref.id].cid;
  1199. // console.log('PROXIMITE ref concernement jarvis_envelope_convexe', this.concernementsByID[ref_cid].sailentEntites);
  1200. let ref_concernement = this.concernementsByID[ref_cid];
  1201. // create the entite ref paper point
  1202. let ref_instance = new paper.SymbolItem(this.paper_symbol_definitions['entite']);
  1203. ref_instance.name = 'entite_ref';
  1204. let entite_ref_pos = {
  1205. x: entite_pos.x + ray * Math.cos((beta*e) * (Math.PI/180)) * this.scale, // met a l'echelle la position du point de l'entite en proximite
  1206. y: entite_pos.y + ray * Math.sin((beta*e) * (Math.PI/180)) * this.scale, // met a l'echelle la position du point de l'entite en proximite
  1207. }
  1208. // console.log(`entite_ref_pos x:${entite_ref_pos.x}, y:${entite_ref_pos.y}`);
  1209. ref_instance.position = new paper.Point(entite_ref_pos);
  1210. // ref_instance.scale(this.scale);
  1211. ref_instance.scale(this.scale*0.75); // met a l'échelle la taille du point et la diminue
  1212. ref_instance.fillColor = '#000';
  1213. ref_instance.item_id = entite_ref.id;
  1214. ref_instance.item_type = 'entite_proximite_reference';
  1215. ref_instance.ref_cid = ref_cid;
  1216. ref_instance.parent_eid = entite.entite.id;
  1217. ref_instance.is_symbol_instance = true;
  1218. ref_g.addChild(ref_instance)
  1219. // create the original concernement contours arround the entite_ref
  1220. let points = [];
  1221. ref_concernement.sailentEntites.forEach(ent => {
  1222. points.push({
  1223. x: (ent.display.ray) * Math.cos(ent.display.alpha * (Math.PI/180)) * this.scale, // met a l'echelle la position du point par rapport a l'entite e proximite
  1224. y: (ent.display.ray) * Math.sin(ent.display.alpha * (Math.PI/180)) * this.scale // met a l'echelle la position du point par rapport a l'entite e proximite
  1225. })
  1226. // - - //
  1227. // concat all the contours points for general contours arround all contours :/ :( (that's a very clear description)
  1228. let p = {
  1229. x: entite_ref_pos.x - entite_pos.x + (ent.display.ray * Math.cos(ent.display.alpha * (Math.PI/180))) * this.scale,
  1230. y: entite_ref_pos.y - entite_pos.y + (ent.display.ray * Math.sin(ent.display.alpha * (Math.PI/180))) * this.scale
  1231. }
  1232. // console.log(`p x:${p.x}, y:${p.y}`);
  1233. allEntiteRefConcernementContourEntites.push({
  1234. display:{
  1235. ray: Math.sqrt(Math.pow(p.x,2)+Math.pow(p.y,2)),
  1236. alpha: parseFloat(Math.atan2(p.y,p.x) * (180/Math.PI)).toFixed(2)
  1237. }
  1238. })
  1239. // - - //
  1240. })
  1241. // convert points to rouded and padded segments props
  1242. let segments = this.getPaddedRoundedSegments(points, scaledown)
  1243. // create "real" Paper Segments from previous segments props
  1244. let paper_segments = [];
  1245. segments.forEach(seg => {
  1246. let paddedSegPoint = {
  1247. x: entite_ref_pos.x+seg.point[0]*scaledown,
  1248. y: entite_ref_pos.y+seg.point[1]*scaledown
  1249. }
  1250. // console.log('paddedSegPoint', paddedSegPoint);
  1251. paper_segments.push(new paper.Segment({
  1252. point: paddedSegPoint,
  1253. handleIn: seg.handleIn,
  1254. handleout: seg.handleOut
  1255. }))
  1256. // - - //
  1257. // concat all the contours points for general contours arround all contours :/ :( (that's a very clear description)
  1258. // let p = {
  1259. // x: (entite_ref_pos.x - entite_pos.x + (ent.display.ray * Math.cos(ent.display.alpha * (Math.PI/180)))),
  1260. // y: (entite_ref_pos.y - entite_pos.y + (ent.display.ray * Math.sin(ent.display.alpha * (Math.PI/180))))
  1261. // }
  1262. // console.log(`p x:${p.x}, y:${p.y}`);
  1263. // allEntiteRefConcernementContourEntites.push({
  1264. // display:{
  1265. // ray: Math.sqrt(Math.pow(paddedSegPoint.x,2)+Math.pow(paddedSegPoint.y,2)),
  1266. // alpha: parseFloat(Math.atan2(paddedSegPoint.y,paddedSegPoint.x) * (180/Math.PI)).toFixed(2)
  1267. // }
  1268. // })
  1269. // - - //
  1270. });
  1271. // create the paper path with previous segments
  1272. const contrs = new paper.Path({
  1273. name: 'contours',
  1274. segments: paper_segments,
  1275. fillColor: 'rgba(255,255,255,0.4)',
  1276. // selected: true,
  1277. strokeColor: '#fff',
  1278. strokeWidth: 1,
  1279. pivot: new paper.Point(this.pos),
  1280. cid: ref_concernement.id
  1281. });
  1282. ref_g.addChild(contrs);
  1283. contrs.sendToBack();
  1284. ref_instance.contour_paper_item_id = contrs.id;
  1285. e++;
  1286. }); // end of loop on proximite for each main entite
  1287. // general contour arround proximité
  1288. // console.log('allEntiteRefConcernementContourEntites', allEntiteRefConcernementContourEntites);
  1289. let genContoursEntite = this.getJarvisEnvelopeConvexeEntites(allEntiteRefConcernementContourEntites);
  1290. // console.log('genContoursEntite', genContoursEntite);
  1291. let points = [];
  1292. genContoursEntite.forEach(ent => {
  1293. points.push({
  1294. x: ent.display.ray * Math.cos(ent.display.alpha * (Math.PI/180)),
  1295. y: ent.display.ray * Math.sin(ent.display.alpha * (Math.PI/180))
  1296. })
  1297. })
  1298. // console.log('points', points);
  1299. let gen_scaledown = 0.16;
  1300. // scaledown = 1;
  1301. // convert points to rouded and padded segments props
  1302. let segments = this.getPaddedRoundedSegments(points, gen_scaledown)
  1303. // create "real" Paper Segments from previous segments props
  1304. let paper_segments = [];
  1305. segments.forEach(seg => {
  1306. paper_segments.push(new paper.Segment({
  1307. point: [entite_pos.x+seg.point[0]*gen_scaledown, entite_pos.y+seg.point[1]*gen_scaledown],
  1308. // point: [seg.point[0], seg.point[1]],
  1309. handleIn: seg.handleIn,
  1310. handleout: seg.handleOut
  1311. }))
  1312. });
  1313. // create the paper path with previous segments
  1314. const genContrs = new paper.Path({
  1315. name: 'gen_contours',
  1316. segments: paper_segments,
  1317. fillColor: 'rgba(255,255,255,0.4)',
  1318. // selected: true,
  1319. strokeColor: '#fff',
  1320. strokeWidth: 1,
  1321. pivot: new paper.Point(this.pos),
  1322. // cid: this.cid
  1323. });
  1324. ref_g.addChild(genContrs);
  1325. genContrs.sendToBack();
  1326. g.addChild(ref_g);
  1327. ref_g.sendToBack();
  1328. } // end of loop on entite wich have proximite
  1329. }
  1330. return g;
  1331. },
  1332. setPaperAgissantes(){
  1333. console.log('setPaperAgissantes');
  1334. let g = new paper.Group({
  1335. pivot: new paper.Point(this.pos),
  1336. name: 'agissantes'
  1337. });
  1338. for (let i = 0; i < this.concernement.revisions_byid[this.concernement.revision_id].entites.length; i++) {
  1339. let entite = this.concernement.revisions_byid[this.concernement.revision_id].entites[i];
  1340. // console.log('agissantes', entite);
  1341. if (entite.entite && entite.entite.agissante) {
  1342. let instance = new paper.SymbolItem(this.paper_symbol_definitions['entite_action']);
  1343. instance.name = 'entite_action';
  1344. instance.position = new paper.Point([this.pos.x + entite.display.pos.x * this.scale, this.pos.y + entite.display.pos.y * this.scale]);
  1345. instance.fillColor = '#000';
  1346. // instance.scale(0.2);
  1347. instance.scale(this.scale);
  1348. instance.item_id = entite.entite.id;
  1349. instance.item_type = 'entite_action';
  1350. instance.is_symbol_instance = true;
  1351. g.addChild(instance)
  1352. }
  1353. }
  1354. return g;
  1355. },
  1356. // setPaperAgissantesIcons(){
  1357. // let g = new paper.Group({
  1358. // pivot: new paper.Point(this.pos),
  1359. // name: 'agissantes_icons'
  1360. // });
  1361. // for (let i = 0; i < this.concernement.revisions_byid[this.concernement.revision_id].entites.length; i++) {
  1362. // let entite = this.concernement.revisions_byid[this.active_revision].entites[i];
  1363. // if (entite.entite && entite.entite.agissante) {
  1364. // let instance = new paper.SymbolItem(this.paper_symbol_definitions['entite_action_icon']);
  1365. // instance.name = 'entite_action';
  1366. // instance.position = new paper.Point([this.pos.x + entite.display.pos.x * this.scale, this.pos.y + entite.display.pos.y * this.scale]);
  1367. // instance.fillColor = '#000';
  1368. // // instance.scale(0.2);
  1369. // instance.scale(this.scale);
  1370. // instance.item_id = entite.entite.id;
  1371. // instance.item_type = 'entite_action';
  1372. // instance.is_symbol_instance = true;
  1373. // g.addChild(instance)
  1374. // }
  1375. // }
  1376. // return g;
  1377. // },
  1378. setPaperPuissanceagirBesoins(update){
  1379. console.log(`setPaperPuissanceagirBesoins cid:${this.concernement.id}, update: ${update}`);
  1380. let g;
  1381. if (update) {
  1382. g = this.paper_main_object.children['puissanceagir_besoins'];
  1383. console.log('REUSING puissanceagir_besoins group', g);
  1384. } else{
  1385. console.log('CREATING puissanceagir_besoins group');
  1386. g = new paper.Group({
  1387. pivot: new paper.Point(this.pos),
  1388. name: 'puissanceagir_besoins'
  1389. });
  1390. }
  1391. if (!g) {
  1392. console.warn('no puissanceagir_besoins group created nor found')
  1393. return;
  1394. }
  1395. let res_fields = ['qui','quoi','ou','avec'];
  1396. let arc = (360 / 16); // unit arc
  1397. let r = (this.ray * this.scale)/5; // unit ray
  1398. let br = r - r/3; // besoin ray
  1399. for (let i = 0; i < this.concernement.besoins.length; i++) {
  1400. let start_a = arc * i; // angle depart (for reponses)
  1401. let center_a = start_a + arc/2; // angle central
  1402. let x = Math.cos(center_a*(Math.PI/180)) * br;
  1403. let y = Math.sin(center_a*(Math.PI/180)) * br;
  1404. // use paper symbol
  1405. let paper_besoin;
  1406. if (update) {
  1407. paper_besoin = this.paper_main_object.getItem({id: this.concernement.besoins[i].paper_id});
  1408. // console.log('REUSING besoin paper item', paper_besoin);
  1409. } else{
  1410. // console.log('CREATING besoin paper item');
  1411. paper_besoin = new paper.SymbolItem(this.paper_symbol_definitions['besoin']);
  1412. paper_besoin.scale(this.scale);
  1413. paper_besoin.item_id = this.concernement.besoins[i].id;
  1414. paper_besoin.item_cid = this.concernement.id;
  1415. paper_besoin.item_type = 'besoin';
  1416. paper_besoin.is_symbol_instance = true;
  1417. g.addChild(paper_besoin)
  1418. // this is retriggering watch concernement and watch concernement.besoins
  1419. this.setBesoinPaperId(paper_besoin.id, this.cid, this.concernement.besoins[i].id);
  1420. }
  1421. console.log(`paper paper_besoin id:${paper_besoin.id}`);
  1422. if (!paper_besoin) {
  1423. console.warn('no paper_besoin item created nor found')
  1424. return;
  1425. }
  1426. paper_besoin.position = new paper.Point([this.pos.x + x, this.pos.y + y]);
  1427. let res_arc = arc / (1 + this.concernement.besoins[i].reponses.length); // unit arc for responses depending responses number
  1428. for (let j = 0; j < this.concernement.besoins[i].reponses.length; j++) {
  1429. let res_a = start_a + res_arc * (j+1); // angle for response line
  1430. for (let f = 0; f < res_fields.length; f++) { // loop through all 4 fields, keep only the last one filled
  1431. if( this.concernement.besoins[i].reponses[j][res_fields[f]] // if field filled
  1432. && (f === res_fields.length -1 || !this.concernement.besoins[i].reponses[j][res_fields[f+1]]) // and is last field or last field filled
  1433. ){
  1434. let rr = this.ray * this.scale - r*f - r/2; // reponse field ray
  1435. let rx = Math.cos(res_a*(Math.PI/180)) * rr;
  1436. let ry = Math.sin(res_a*(Math.PI/180)) * rr;
  1437. // use paper symbol
  1438. let paper_reponse;
  1439. let paper_reponse_id = this.concernement.besoins[i].reponses[j].paper_id;
  1440. if (update && paper_reponse_id) {
  1441. // console.log('paper_reponse_id', paper_reponse_id);
  1442. paper_reponse = this.paper_main_object.getItem({id: paper_reponse_id});
  1443. // console.log('REUSING reponse paper item', paper_reponse);
  1444. } else {
  1445. // console.log('CREATING reponse paper item', paper_reponse_id, this.concernement.besoins[i]);
  1446. // debugger;
  1447. paper_reponse = new paper.SymbolItem(this.paper_symbol_definitions['reponse']);
  1448. paper_reponse.scale(this.scale);
  1449. paper_reponse.item_id = this.concernement.besoins[i].reponses[j].id;
  1450. paper_reponse.item_bid = this.concernement.besoins[i].id;
  1451. paper_reponse.item_cid = this.concernement.id;
  1452. paper_reponse.item_type = 'reponse';
  1453. paper_reponse.is_symbol_instance = true;
  1454. this.setBesoinPaperId(paper_reponse.id, this.cid, this.concernement.besoins[i].id, this.concernement.besoins[i].reponses[j].id);
  1455. g.addChild(paper_reponse);
  1456. }
  1457. if (!paper_reponse) {
  1458. console.warn('no paper_reponse item created nor found')
  1459. return;
  1460. }
  1461. paper_reponse.position = new paper.Point([this.pos.x + rx, this.pos.y + ry]);
  1462. }
  1463. }
  1464. }
  1465. }
  1466. return g;
  1467. },
  1468. // resetPaperBesoinReponsePos(){
  1469. // console.log(`resetPaperBesoinReponsePos cid:${this.concernement.id}`);
  1470. // let res_fields = ['qui','quoi','ou','avec'];
  1471. // let arc = (360 / 16); // unit arc
  1472. // let r = (this.ray * this.scale)/5; // unit ray
  1473. // for (let i = 0; i < this.concernement.besoins.length; i++) {
  1474. // let start_a = arc * i;
  1475. // let res_arc = arc / (1 + this.concernement.besoins[i].reponses.length); // unit arc for responses depending responses number
  1476. // for (let j = 0; j < this.concernement.besoins[i].reponses.length; j++) {
  1477. // let res_a = start_a + res_arc * (j+1); // angle for response line
  1478. // for (let f = 0; f < res_fields.length; f++) { // loop through all 4 fields, keep only the last one filled
  1479. // if( this.concernement.besoins[i].reponses[j][res_fields[f]] // if field filled
  1480. // && (f === res_fields.length -1 || !this.concernement.besoins[i].reponses[j][res_fields[f+1]]) // and is last field or last field filled
  1481. // ){
  1482. // let rr = this.ray * this.scale - r*f - r/2; // reponse field ray
  1483. // let rx = Math.cos(res_a*(Math.PI/180)) * rr;
  1484. // let ry = Math.sin(res_a*(Math.PI/180)) * rr;
  1485. // let paper_id = this.concernement.besoins[i].reponses[j].paper_id;
  1486. // console.log('paper_id', paper_id);
  1487. // let paper_reponse = this.paper_main_object.getItem({id: paper_id});
  1488. // console.log('paper_reponse', paper_reponse);
  1489. // paper_reponse.position = new paper.Point([this.pos.x + rx, this.pos.y + ry]);
  1490. // }
  1491. // }
  1492. // }
  1493. // }
  1494. // },
  1495. setPaperDoleances(){
  1496. let g = new paper.Group({
  1497. pivot: new paper.Point({x:0,y:0}),
  1498. name: `doleances`
  1499. });
  1500. this.concernement.doleances.forEach((d) => {
  1501. g.addChild(this.setPaperDoleanceSteps(d))
  1502. });
  1503. return g;
  1504. },
  1505. setPaperDoleanceSteps(doleance){
  1506. let g = new paper.Group({
  1507. pivot: new paper.Point({x:0,y:0}),
  1508. name: `doleance_${doleance.id}`,
  1509. doleance_id: doleance.id,
  1510. visible: false
  1511. });
  1512. // let doleance = this.concernement.doleances[0];
  1513. let all_fields = [
  1514. [
  1515. 'leprobleme',
  1516. 'lenquete',
  1517. {
  1518. fieldname: 'groupesinterets',
  1519. fields: [
  1520. 'groupe_interets',
  1521. 'accorder_interets',
  1522. 'formuler',
  1523. ]
  1524. }
  1525. ],
  1526. [
  1527. 'entite_addresse_doleance',
  1528. 'comment_ennonce_doleance',
  1529. 'aqui_addresse_doleance',
  1530. {
  1531. fieldname: 'reception_traitement',
  1532. fields: [
  1533. 'entite_adressee',
  1534. 'doleance_formulee',
  1535. 'traite_doleance',
  1536. 'entite_recoit_doleance',
  1537. ]
  1538. }
  1539. ],
  1540. [
  1541. 'entites_decisionnaires',
  1542. 'decision_formule',
  1543. {
  1544. fieldname: 'mise_en_oeuvre_decision',
  1545. fields: [
  1546. 'entite_adresse_decision',
  1547. 'formule_decision',
  1548. 'entite_metenoeuvre_decisio',
  1549. ]
  1550. }
  1551. ],
  1552. [
  1553. 'entite_adresse_application',
  1554. 'aqui_adresse_decision',
  1555. 'comment_formule_decision',
  1556. {
  1557. fieldname: 'receptions_et_applications',
  1558. fields: [
  1559. 'applique_decision',
  1560. 'formule_decision_applic',
  1561. 'entite_recoit_decision',
  1562. ]
  1563. },
  1564. 'probleme_initial_resolu',
  1565. 'oui_nouvelle_situation',
  1566. 'non_adresse_doleance',
  1567. ]
  1568. ];
  1569. var r = this.ray * this.scale * 0.8; // ray
  1570. var dr = r/2; // demi ray
  1571. // var pcr = 2*this.scale; // petits cercle rayon
  1572. // https://fr.wikipedia.org/wiki/Trigonom%C3%A9trie#/media/Fichier:Unit_circle_angles_color.svg
  1573. // https://fr.wikipedia.org/wiki/Identit%C3%A9_trigonom%C3%A9trique_pythagoricienne#Preuve_utilisant_le_cercle_unit%C3%A9
  1574. // radians = degrees * (pi/180)
  1575. // degrees = radians * (180/pi)
  1576. // Points for 45° axes
  1577. let m = Math.sin(45*(Math.PI/180)) * r; // x = y for rayon
  1578. let n = Math.sin(45*(Math.PI/180)) * r/2; // x = y for demi rayon
  1579. let o = Math.cos(22.5*(Math.PI/180)) * r; // x @ 22.5° for rayon
  1580. let p = Math.sin(22.5*(Math.PI/180)) * r; // y @ 22.5° for rayon
  1581. let o_d = Math.cos(22.5*(Math.PI/180)) * r/2; // x @ 22.5° for demi rayon
  1582. let p_d = Math.sin(22.5*(Math.PI/180)) * r/2; // y @ 22.5° for demi rayon
  1583. let step_Style = {
  1584. strokeColor: '#fff',
  1585. strokeWidth: 2,
  1586. fillColor: "rgba(255, 255, 255, 0.3)"
  1587. }
  1588. // let fontsize = 4;
  1589. //
  1590. // CAMENBERT STATIQUES
  1591. //
  1592. // l'enquete
  1593. //
  1594. // camenbert
  1595. if (doleance.lenquete) {
  1596. let cam = new paper.Path({...step_Style, ...{
  1597. item_type: 'doleance_step',
  1598. item_id: `lenquete`,
  1599. did: doleance.id,
  1600. field: 'lenquete',
  1601. field_index: null
  1602. }
  1603. });
  1604. cam.add({x: this.pos.x , y: this.pos.y + dr});
  1605. cam.lineTo({x: this.pos.x, y: this.pos.y + r});
  1606. cam.arcTo({x: this.pos.x - p, y: this.pos.y + o}, {x: this.pos.x - m, y: this.pos.y + m});
  1607. cam.lineTo({x: this.pos.x - n, y: this.pos.y + n});
  1608. cam.arcTo({x: this.pos.x - p_d, y: this.pos.y + o_d}, {x: this.pos.x , y: this.pos.y + dr});
  1609. // texte
  1610. // enquete.addChild(new paper.PointText({
  1611. // point: {
  1612. // x:this.pos.x + Math.sin(22.5*(Math.PI/180)) * r*0.75,
  1613. // y:this.pos.y + Math.cos(22.5*(Math.PI/180)) * r*0.75
  1614. // },
  1615. // content: doleance['lenquete'],
  1616. // fontSize: fontsize,
  1617. // fillColor: '#fff',
  1618. // justification: 'center',
  1619. // locked: true
  1620. // }));
  1621. g.addChild(cam);
  1622. }
  1623. //
  1624. // probleme_initial_resolu
  1625. //
  1626. // camenbert
  1627. if(doleance.probleme_initial_resolu === 0 || doleance.probleme_initial_resolu === 1){
  1628. let rescam = new paper.Path({...step_Style, ...{
  1629. closed: true,
  1630. item_type: 'doleance_step',
  1631. item_id: `probleme_initial_resolu`,
  1632. did: doleance.id,
  1633. field: 'probleme_initial_resolu',
  1634. field_index: null
  1635. }
  1636. });
  1637. rescam.add({x: this.pos.x + n, y: this.pos.y + n});
  1638. rescam.lineTo({x: this.pos.x + m , y: this.pos.y + m});
  1639. rescam.arcTo({x: this.pos.x + p, y: this.pos.y + o}, {x: this.pos.x, y: this.pos.y + r});
  1640. rescam.lineTo({x: this.pos.x, y: this.pos.y + dr});
  1641. rescam.arcTo({x: this.pos.x + p_d, y: this.pos.y + o_d}, {x: this.pos.x + n, y: this.pos.y + n});
  1642. // texte
  1643. // resolution.addChild(new paper.PointText({
  1644. // point: {
  1645. // x:this.pos.x - Math.sin(22.5*(Math.PI/180)) * r*0.75,
  1646. // y:this.pos.y + Math.cos(22.5*(Math.PI/180)) * r*0.75
  1647. // },
  1648. // content: doleance['probleme_initial_resolu'] ? doleance['oui_nouvelle_situation'] : doleance['non_adresse_doleance'],
  1649. // fontSize: fontsize,
  1650. // fillColor: '#fff',
  1651. // justification: 'center'
  1652. // }));
  1653. g.addChild(rescam)
  1654. }
  1655. //
  1656. // MULTIPLE FIELDS
  1657. //
  1658. let multiple_fields = [
  1659. { field_name: 'groupesinterets', arc: 45, decalage: -45 },
  1660. { field_name: 'reception_traitement', arc: 90, decalage: -90 },
  1661. { field_name: 'mise_en_oeuvre_decision', arc: 90, decalage: -180 },
  1662. { field_name: 'receptions_et_applications', arc: 45, decalage: 90 }
  1663. ]
  1664. multiple_fields.forEach((mf, j) => {
  1665. for (let i = 0, l = doleance[mf.field_name].length, a = mf.arc/l; i < l; i++) {
  1666. // let gi = new paper.Group({
  1667. // item_type: 'doleance_step',
  1668. // item_id: 'lenquete',
  1669. // item_field: mf.field_name,
  1670. // item_index: i
  1671. // });
  1672. //camenbert
  1673. let x1= this.pos.x + Math.sin((mf.decalage- a*i)*(Math.PI/180)) * dr,
  1674. y1= this.pos.y + Math.cos((mf.decalage- a*i)*(Math.PI/180)) * dr;
  1675. let x2= this.pos.x + Math.sin((mf.decalage- a*i)*(Math.PI/180)) * r,
  1676. y2= this.pos.y + Math.cos((mf.decalage- a*i)*(Math.PI/180)) * r;
  1677. let x3= this.pos.x + Math.sin((mf.decalage- a*(i+1))*(Math.PI/180)) * r,
  1678. y3= this.pos.y + Math.cos((mf.decalage- a*(i+1))*(Math.PI/180)) * r;
  1679. let x3t= this.pos.x + Math.sin((mf.decalage- a*(i+0.5))*(Math.PI/180)) * r,
  1680. y3t= this.pos.y + Math.cos((mf.decalage- a*(i+0.5))*(Math.PI/180)) * r;
  1681. let x4= this.pos.x + Math.sin((mf.decalage- a*(i+1))*(Math.PI/180)) * dr,
  1682. y4= this.pos.y + Math.cos((mf.decalage- a*(i+1))*(Math.PI/180)) * dr;
  1683. let x4t= this.pos.x + Math.sin((mf.decalage- a*(i+0.5))*(Math.PI/180)) * dr,
  1684. y4t= this.pos.y + Math.cos((mf.decalage- a*(i+0.5))*(Math.PI/180)) * dr;
  1685. let x5= this.pos.x + Math.sin((mf.decalage- a*(i+0.5))*(Math.PI/180)) * r*0.75,
  1686. y5= this.pos.y + Math.cos((mf.decalage- a*(i+0.5))*(Math.PI/180)) * r*0.75;
  1687. let p = new paper.Path({...step_Style, ...{
  1688. item_type: 'doleance_step',
  1689. item_id: `${mf.field_name}-${i}`,
  1690. did: doleance.id,
  1691. field: mf.field_name,
  1692. field_index: i
  1693. }
  1694. });
  1695. p.add([x1,y1]);
  1696. p.lineTo([x2,y2]);
  1697. p.arcTo([x3t,y3t], [x3,y3]);
  1698. p.lineTo([x4,y4]);
  1699. p.arcTo([x4t,y4t], [x1,y1]);
  1700. g.addChild(p);
  1701. // gi.addChild(p);
  1702. // // text
  1703. // gi.addChild(new paper.PointText({
  1704. // point: {x:x5,y:y5},
  1705. // content: `${j}-${i}`,
  1706. // fontSize: fontsize,
  1707. // fillColor: '#fff',
  1708. // justification: 'center'
  1709. // }))
  1710. // g.addChild(gi)
  1711. }
  1712. });
  1713. // POINTS CARDINAUX
  1714. let cardinal_Style = {
  1715. strokeColor: '#fff',
  1716. strokeWidth: 2,
  1717. fillColor: "rgba(255, 255, 255, 0.9)"
  1718. }
  1719. // leprobleme
  1720. if (doleance.leprobleme) {
  1721. g.addChild(new paper.Path.Circle({
  1722. center: [this.pos.x, this.pos.y + r],
  1723. radius: 3 * this.scale,
  1724. style: cardinal_Style,
  1725. item_type: 'doleance_step',
  1726. item_id: `leprobleme`,
  1727. did: doleance.id,
  1728. field: 'leprobleme'
  1729. }));
  1730. }
  1731. // adresse de la doleance
  1732. if (doleance.entite_addresse_doleance || doleance.aqui_addresse_doleance || doleance.comment_ennonce_doleance) {
  1733. g.addChild(new paper.Path.Circle({
  1734. center: [this.pos.x - r, this.pos.y],
  1735. radius: 3 * this.scale,
  1736. style: cardinal_Style,
  1737. item_type: 'doleance_step',
  1738. item_id: `adresse_de_la_doleance`,
  1739. did: doleance.id,
  1740. field: 'adresse_de_la_doleance'
  1741. }));
  1742. }
  1743. // decision
  1744. if (doleance.entites_decisionnaires || doleance.decision_formule) {
  1745. g.addChild(new paper.Path.Circle({
  1746. center: [this.pos.x, this.pos.y - r],
  1747. radius: 3 * this.scale,
  1748. style: cardinal_Style,
  1749. item_type: 'doleance_step',
  1750. item_id: `decision`,
  1751. did: doleance.id,
  1752. field: 'decision'
  1753. }));
  1754. }
  1755. // adresse_de_la_decision
  1756. if (doleance.entite_adresse_application || doleance.aqui_adresse_decision || doleance.comment_formule_decision) {
  1757. g.addChild(new paper.Path.Circle({
  1758. center: [this.pos.x + r, this.pos.y],
  1759. radius: 3 * this.scale,
  1760. style: cardinal_Style,
  1761. item_type: 'doleance_step',
  1762. item_id: `adresse_de_la_decision`,
  1763. did: doleance.id,
  1764. field: 'adresse_de_la_decision'
  1765. }));
  1766. }
  1767. return g;
  1768. },
  1769. // mapitem visibility
  1770. handleMapitemVisibility(state){
  1771. this.is_visible = state;
  1772. this.paper_main_object.visible = this.is_visible;
  1773. },
  1774. // PAPER VISIBILITY
  1775. handlePaperVisibilityOnBeforeOpen(){
  1776. // // agissantes
  1777. // if (this.concernement.has_agissantes && this.map_mode === "action") {
  1778. // if (!this.is_open) {
  1779. // this.paper_main_object.children.agissantes_icons.visible = true;
  1780. // } else {
  1781. // this.paper_main_object.children.agissantes_icons.visible = false;
  1782. // }
  1783. // }
  1784. // superposition
  1785. // scale down superposed entites on open
  1786. let entites_superposes = this.paper_main_object.children['entites_superposes'];
  1787. if(entites_superposes){
  1788. for(let paper_item of entites_superposes.children) {
  1789. paper_item.scale(0.25)
  1790. }
  1791. }
  1792. // proximite
  1793. // scale down proximite entites on open
  1794. let entites_proximites = this.paper_main_object.children['entites_proximites'];
  1795. if(entites_proximites){
  1796. for(let paper_item of entites_proximites.children) {
  1797. paper_item.scale(0.25)
  1798. }
  1799. }
  1800. },
  1801. handlePaperVisibilityOnOpened(){},
  1802. handlePaperVisibilityOnBeforeClose(){
  1803. // superposition
  1804. // scale up superposed entites on open
  1805. let entites_superposes = this.paper_main_object.children['entites_superposes'];
  1806. if(entites_superposes){
  1807. for(let paper_item of entites_superposes.children) {
  1808. paper_item.scale(4)
  1809. }
  1810. }
  1811. // proximites
  1812. // scale up proximites entites on open
  1813. let entites_proximites = this.paper_main_object.children['entites_proximites'];
  1814. if(entites_proximites){
  1815. for(let paper_item of entites_proximites.children) {
  1816. paper_item.scale(4)
  1817. }
  1818. }
  1819. },
  1820. handlePaperVisibilityOnClosed(){
  1821. // // agissantes
  1822. // if (this.concernement.has_agissantes && this.map_mode === "action") {
  1823. // if (!this.is_open) {
  1824. // this.paper_main_object.children.agissantes_icons.visible = true;
  1825. // } else {
  1826. // this.paper_main_object.children.agissantes_icons.visible = false;
  1827. // }
  1828. // }
  1829. },
  1830. handlePaperVisibilityOnAfterEnginUpdate(){
  1831. // contours focused
  1832. let fc, sc, sw;
  1833. if (!this.isFocused()){
  1834. fc = "rgba(255,255,255,0.1)";
  1835. }else{
  1836. fc = "rgba(255,255,255,0.4)";
  1837. if (this.concernement.can_update) {
  1838. sc = "#01ffe2";
  1839. if (this.is_hover) {
  1840. sw = 2;
  1841. }else{
  1842. sw = 1;
  1843. }
  1844. } else {
  1845. if (this.is_hover) {
  1846. sc = "#01ffe2";
  1847. sw = 2;
  1848. }else{
  1849. sc = "#fff";
  1850. sw = 1;
  1851. }
  1852. }
  1853. }
  1854. this.paper_main_object.children['contours'].fillColor = fc
  1855. this.paper_main_object.children['contours'].strokeColor = sc;
  1856. this.paper_main_object.children['contours'].strokeWidth = sw;
  1857. // contours visibility
  1858. if (!this.is_open
  1859. || (this.is_open && this.map_mode !== "puissancedagir" && this.map_mode !== "doleancer")) {
  1860. this.paper_main_object.children['contours'].visible = true;
  1861. } else {
  1862. this.paper_main_object.children['contours'].visible = false;
  1863. }
  1864. // proximite
  1865. if (this.concernement.has_proximites) {
  1866. if (this.map_mode === "proximite") {
  1867. this.paper_main_object.children.entites_proximites.visible = true;
  1868. }else{
  1869. this.paper_main_object.children.entites_proximites.visible = false;
  1870. }
  1871. }
  1872. // superposition
  1873. if (this.concernement.has_superpositions) {
  1874. if (this.map_mode === "superposition") {
  1875. this.paper_main_object.children.entites_superposes.visible = true;
  1876. // highlight of entite part of opened superposition
  1877. let group = this.paper_main_object.children['entites_superposes'];
  1878. if(group){
  1879. if (this.$route.query.superposition_id) {
  1880. let superposition_id = this.$route.query.superposition_id;
  1881. if(superposition_id){
  1882. // let ids = superposition_id.match(/(\d+)_(\d+)__(\d+)_(\d+)/i)
  1883. // group.children.forEach((item) => {
  1884. // if ( (this.cid === parseInt(ids[1]) && item.item_id === parseInt(ids[2]))
  1885. // || (this.cid === parseInt(ids[3]) && item.item_id === parseInt(ids[4])) ) {
  1886. // item.definition = this.paper_symbol_definitions.entite_hover;
  1887. // if(!item.focused){
  1888. // item.scale(2)
  1889. // item.focused = true;
  1890. // }
  1891. // } else if(!this.is_hover) {
  1892. // item.definition = this.paper_symbol_definitions.entite;
  1893. // if (item.focused) {
  1894. // item.scale(0.5)
  1895. // item.focused = false;
  1896. // }
  1897. // }
  1898. // })
  1899. }
  1900. }else{
  1901. group.children.forEach((item) => {
  1902. if(!this.is_hover) {
  1903. item.definition = this.paper_symbol_definitions.entite;
  1904. if (item.focused) {
  1905. item.scale(0.5)
  1906. item.focused = false;
  1907. }
  1908. }
  1909. })
  1910. }
  1911. }
  1912. } else {
  1913. this.paper_main_object.children.entites_superposes.visible = false;
  1914. }
  1915. }
  1916. // // puissance d'agir
  1917. // if (this.concernement.has_puissancedagir) {
  1918. // if (this.map_mode === "puissancedagir") {
  1919. // if (!this.is_open) {
  1920. // this.paper_main_object.children.puissanceagir_icon.visible = true; // if not opened and has_puissancedagir draw the puissance d'agir icone
  1921. // } else {
  1922. // this.paper_main_object.children.puissanceagir_icon.visible = false;
  1923. // }
  1924. // } else {
  1925. // this.paper_main_object.children.puissanceagir_icon.visible = false;
  1926. // }
  1927. // }
  1928. // agissantes
  1929. // if (this.concernement.has_agissantes) {
  1930. // if (this.map_mode !== "action") {
  1931. // this.paper_main_object.children.agissantes_icons.visible = false;
  1932. // } else if(!this.is_open && !this.is_closing){
  1933. // this.paper_main_object.children.agissantes_icons.visible = true;
  1934. // }
  1935. // }
  1936. // doleance
  1937. if (this.concernement.has_doleance) {
  1938. if (this.map_mode === "doleancer") {
  1939. if (!this.is_open) {
  1940. // this.paper_main_object.children.doleance_icon.visible = true;
  1941. } else {
  1942. // this.paper_main_object.children.doleance_icon.visible = false;
  1943. // display the right (opened) doleance
  1944. let from = null
  1945. let to = this.concernement.opened_doleance.id;
  1946. this.concernement.doleances.forEach((d) => {
  1947. // this.paper_main_object.children.doleances.children[`doleance_${d.id}`].visible = d.id === this.concernement.opened_doleance.id;
  1948. if (this.paper_main_object.children.doleances.children[`doleance_${d.id}`].visible) {
  1949. from = d.id
  1950. }
  1951. })
  1952. // console.log(`opened_doleance from:${from}, to:${to}`);
  1953. if (from && from !== to) {
  1954. this.initDoleanceTransition(from, to);
  1955. } else if(!this.doleance_transition) {
  1956. this.concernement.doleances.forEach((d) => {
  1957. this.paper_main_object.children.doleances.children[`doleance_${d.id}`].visible = d.id === this.concernement.opened_doleance.id;
  1958. })
  1959. }
  1960. }
  1961. } else {
  1962. // this.paper_main_object.children.doleance_icon.visible = false;
  1963. }
  1964. }
  1965. // focus on opened entite
  1966. if (this.is_open && (this.map_mode === 'terraindevie' || this.map_mode === 'action')) {
  1967. let group = this.map_mode === 'terraindevie' ? this.paper_main_object.children['entites'] : this.paper_main_object.children['agissantes'];
  1968. if(group){
  1969. group.children.forEach((item) => {
  1970. if (this.opened_entite_id && item.item_id === parseInt(this.opened_entite_id) && item.item_type !== 'entite_hidden') {
  1971. // switch symbole definition to hover
  1972. item.definition = item.item_type === 'entite' ? this.paper_symbol_definitions.entite_hover : this.paper_symbol_definitions.entite_action_hover;
  1973. } else {
  1974. // switch back symbole definition to normal
  1975. if ((!this.hover_elmt || item.item_id !== this.hover_elmt.id) && item.item_type !== 'entite_hidden') {
  1976. item.definition = item.item_type === 'entite' ? this.paper_symbol_definitions.entite : this.paper_symbol_definitions.entite_action;
  1977. }
  1978. }
  1979. })
  1980. }
  1981. let labels_group = this.paper_main_object.children['entites'].children['entites_labels'];
  1982. if (labels_group) {
  1983. labels_group.children.forEach((item) => {
  1984. if (this.opened_entite_id && item.item_id === parseInt(this.opened_entite_id) && item.item_type !== 'entite_hidden') {
  1985. item.bringToFront();
  1986. item.children[0].strokeColor = "#01ffe2";
  1987. }else{
  1988. // item.children[0].strokeColor = "#fff";
  1989. }
  1990. })
  1991. }
  1992. }
  1993. },
  1994. initDoleanceTransition(from, to){
  1995. if (!this.doleance_transition) {
  1996. this.doleance_transition = true
  1997. // console.log(`initDoleanceTransition from:${from}, to:${to}`);
  1998. let from_pg = this.paper_main_object.children.doleances.children[`doleance_${from}`]
  1999. from_pg.visible = true;
  2000. from_pg.opacity = 1;
  2001. let to_pg = this.paper_main_object.children.doleances.children[`doleance_${to}`]
  2002. to_pg.visible = true;
  2003. to_pg.opacity = 0;
  2004. let bg = this.paper_main_object.children.doleance_bg;
  2005. // // fade out the current visible cercle politique then fade in the new one
  2006. new Tween.Tween({o: 1})
  2007. .to({
  2008. o: 0
  2009. }, 600)
  2010. .onUpdate((obj) => {
  2011. console.log(`tween update. o=${obj.o}`);
  2012. from_pg.opacity = bg.opacity = obj.o;
  2013. })
  2014. .onComplete((obj) => {
  2015. new Tween.Tween({o: 0})
  2016. .to({
  2017. o: 1
  2018. }, 900)
  2019. .onUpdate((objb) => {
  2020. to_pg.opacity = bg.opacity = objb.o;
  2021. })
  2022. .onComplete((obj) => {
  2023. from_pg.visible = false;
  2024. from_pg.opacity = 1;
  2025. to_pg.opacity = 1;
  2026. this.doleance_transition = false
  2027. })
  2028. .delay(500)
  2029. .easing(Tween.Easing.Quadratic.InOut)
  2030. .start();
  2031. })
  2032. .easing(Tween.Easing.Quadratic.Out)
  2033. .start();
  2034. }
  2035. },
  2036. onIsHover(){
  2037. // handle layer z-index
  2038. if (this.is_hover) {
  2039. this.paper_main_object.bringToFront();
  2040. } else {
  2041. // mapitem can be hover while an other mapitem is open if it is superposed (superposition) to the currently opened mapitem
  2042. // in this case don't send it back
  2043. if (!this.opened_concernement) {
  2044. this.paper_main_object.sendToBack();
  2045. }
  2046. }
  2047. // hightlight superposed entites on focus
  2048. let entites_superposes = this.paper_main_object.children['entites_superposes'];
  2049. // console.log('entites_superposes.children', entites_superposes.children);
  2050. if(entites_superposes){
  2051. for(let paper_item of entites_superposes.children) {
  2052. if (this.is_hover) {
  2053. paper_item.definition = this.paper_symbol_definitions.entite_hover;
  2054. // paper_item.scale(2)
  2055. } else {
  2056. paper_item.definition = this.paper_symbol_definitions.entite;
  2057. // paper_item.scale(0.5)
  2058. }
  2059. }
  2060. }
  2061. },
  2062. /*
  2063. * PAPER EVENTS
  2064. */
  2065. initPaperEvents(){
  2066. this.paper_main_object.onMouseLeave = function(event){
  2067. if (this.wait) {
  2068. // when we are reloading entites par exemple
  2069. // also handled by watch and onMouseMove for more reactivity
  2070. document.body.style.cursor = "wait";
  2071. } else {
  2072. if (!this.opened_concernement && this.isFocused()) { // only if no concernement is opened
  2073. this.resetHoverElmt();
  2074. document.body.style.cursor = "auto";
  2075. }
  2076. if (this.is_open) {
  2077. document.body.style.cursor = "auto";
  2078. }
  2079. }
  2080. }.bind(this);
  2081. this.paper_main_object.onMouseMove = function(event){
  2082. // console.log(`onmousemove ${this.id}`, this.cartouch_is_opened);
  2083. // prevent hover map item mouse event if cartouch is opened
  2084. if (this.cartouch_is_opened && this.map_mode !== "superposition") return;
  2085. if (!this.is_open) {
  2086. if (!this.opened_concernement) { // only if no concernement is opened and is this focused
  2087. if(this.isFocused()){
  2088. if (this.map_mode === 'superposition') {
  2089. // get the superposed entite
  2090. this.setHoverElmt({
  2091. type: 'superposition',
  2092. id: this.id,
  2093. cid: this.cid,
  2094. eid: this.superposedEntiteID
  2095. });
  2096. } else{
  2097. this.setHoverElmt({
  2098. type: 'concernement',
  2099. id: this.id,
  2100. cid: this.cid
  2101. });
  2102. }
  2103. document.body.style.cursor = "pointer";
  2104. }
  2105. } else if (this.map_mode === 'superposition'){
  2106. // if this mapitem is superposed to the opened mapitem
  2107. if(this.opened_concernement.all_superposed_concernements_id.indexOf(this.cid) >= 0){
  2108. this.setHoverElmt({
  2109. type: 'superposition',
  2110. id: this.id,
  2111. cid: this.cid,
  2112. eid: this.superposedEntiteID
  2113. });
  2114. document.body.style.cursor = "pointer";
  2115. }
  2116. }
  2117. } else {
  2118. // reset all proximity contrs stroke to white
  2119. if (this.paper_main_object.children['entites_proximites_references']) {
  2120. this.paper_main_object.children['entites_proximites_references'].getItems({name:'contours'}).forEach((contr) => {
  2121. contr.strokeColor = '#fff';
  2122. })
  2123. }
  2124. // reset all entite labels stroke to white
  2125. if (this.paper_main_object.children['entites'] && this.paper_main_object.children['entites'].children['entites_labels']) {
  2126. this.paper_main_object.children['entites'].children['entites_labels'].children.forEach((label) => {
  2127. if (!this.opened_entite_id || label.item_id != parseInt(this.opened_entite_id)) {
  2128. label.children['label_bg'].strokeColor = '#fff';
  2129. }
  2130. })
  2131. }
  2132. // lets define some options regarding the map_mode
  2133. let paper_group_tohit;
  2134. switch (this.map_mode) {
  2135. case "terraindevie":
  2136. paper_group_tohit = this.paper_main_object.children['entites'];
  2137. break;
  2138. case "proximite":
  2139. paper_group_tohit = this.paper_main_object.children['entites_proximites_references'];
  2140. break;
  2141. case "superposition":
  2142. paper_group_tohit = this.paper_main_object.children['entites_superposes'];
  2143. break;
  2144. case "action":
  2145. paper_group_tohit = this.paper_main_object.children['agissantes'];
  2146. break;
  2147. case "puissancedagir":
  2148. paper_group_tohit = this.paper_main_object.children['puissanceagir_besoins'];
  2149. break;
  2150. case "doleancer":
  2151. if(this.paper_main_object.children['doleances']){
  2152. paper_group_tohit = this.paper_main_object.children['doleances'].children[`doleance_${this.concernement.opened_doleance.id}`];
  2153. }
  2154. break;
  2155. }
  2156. let result = paper_group_tohit ? paper_group_tohit.hitTest(event.point) : null;
  2157. // console.log('move result', result);
  2158. if (this.wait) {
  2159. // when we are reloading entites par exemple
  2160. // also handled by watch for more reactivity
  2161. document.body.style.cursor = "wait";
  2162. } else if (result && result.item.item_id && (result.item.name != "label_click_zone" || this.detailsZoomValue > 2)) {
  2163. // console.log('move has result', result);
  2164. let new_hover_elmt = {
  2165. paper_id: result.item.id,
  2166. type: result.item.item_type,
  2167. id: result.item.item_id
  2168. };
  2169. switch (result.item.item_type) {
  2170. case "entite_proximite_reference":
  2171. new_hover_elmt.ref_cid = result.item.ref_cid;
  2172. new_hover_elmt.parent_eid = result.item.parent_eid;
  2173. // set the mouse overed contrs to blue
  2174. // contour_paper_item_id is recorded when creating the full paper objects in setPaperEntitesProximiteReferences()
  2175. let contrs_paper_id = result.item.contour_paper_item_id;
  2176. let contrs_paper_obj = result.item.parent.getItem({id: contrs_paper_id});
  2177. contrs_paper_obj.strokeColor = "#01ffe2";
  2178. break;
  2179. case "besoin":
  2180. new_hover_elmt.no_popup = true;
  2181. break;
  2182. case "reponse":
  2183. new_hover_elmt.bid = result.item.item_bid;
  2184. new_hover_elmt.cid = result.item.item_cid;
  2185. new_hover_elmt.no_popup = true;
  2186. break;
  2187. case "entite":
  2188. case "entite_action":
  2189. if(result.item.name == "label_click_zone"){
  2190. // bring front the label in case of overlaping
  2191. result.item.parent.bringToFront();
  2192. result.item.parent.children[0].strokeColor = "#01ffe2";
  2193. }
  2194. break;
  2195. }
  2196. if (!this.hover_elmt || new_hover_elmt.paper_id !== this.hover_elmt.paper_id) {
  2197. // console.log(`before setHoverElmt ${this.id}`);
  2198. if (this.detailsZoomValue <= 2) {
  2199. this.setHoverElmt(new_hover_elmt);
  2200. }
  2201. }
  2202. document.body.style.cursor = "pointer";
  2203. } else {
  2204. // console.log('move no result');
  2205. this.resetHoverElmt();
  2206. if (this.detailsZoomValue > 1) {
  2207. document.body.style.cursor = "grab";
  2208. } else {
  2209. document.body.style.cursor = "auto";
  2210. }
  2211. }
  2212. }
  2213. }.bind(this);
  2214. this.paper_main_object.onClick = async function(event){
  2215. console.log('paper concernement onClick');
  2216. // prevent hover map item mouse event if cartouch is opened
  2217. if (this.cartouch_is_opened) return;
  2218. if (!this.is_open) { // si ce concernement n'est pas ouvet
  2219. console.log('mapitem is NOT opened');
  2220. if (!this.opened_concernement) { // si aucun concernement n'est ouvert
  2221. console.log(`Open me ${this.id}`);
  2222. // push route (keep the hash for map_mode)
  2223. // wait for routing to be finished before opening the mapItem
  2224. let params = {cid: parseInt(this.cid)}
  2225. let query = {mapitemid: this.id};
  2226. if (this.map_mode === "superposition") {
  2227. params.eid = this.superposedEntiteID
  2228. query.superposition_cluster_index = this.mapitem.superposition_cluster_index;
  2229. }
  2230. await this.$router.push({
  2231. name: 'concernement',
  2232. params: params,
  2233. query: query,
  2234. hash: `#${this.map_mode}`
  2235. });
  2236. // open/close all concernements
  2237. this.openCloseConcernements(this.cid, this.id)
  2238. // reset the mousehover
  2239. this.resetHoverElmt();
  2240. } else if (this.map_mode === 'superposition'){ // si un concernement est ouvert et qu'on est en mode superposition
  2241. // if this mapitem is superposed to the opened mapitem
  2242. if(this.opened_concernement.all_superposed_concernements_id.indexOf(this.cid) >= 0){
  2243. // push route (keep the hash for map_mode)
  2244. // wait for routing to be finished before opening the mapItem
  2245. console.log('click on superposed this.mapitem.superposition_cluster_index', this.mapitem.superposition_cluster_index);
  2246. await this.$router.push({
  2247. name: 'concernement',
  2248. params: {cid: this.opened_concernement.cid, eid: this.$route.params.eid},
  2249. query: {
  2250. mapitemid: this.opened_concernement.opened_mapitem_id,
  2251. superposition_cluster_index: this.mapitem.superposition_cluster_index,
  2252. superposed_cid: this.cid
  2253. },
  2254. hash: `#${this.map_mode}`
  2255. });
  2256. }
  2257. }
  2258. } else { // si ce concernement est ouvert
  2259. console.log('mapitem is opened');
  2260. // do not click if we were dragging
  2261. if (this.is_dragging) {
  2262. this.is_dragging = false;
  2263. return;
  2264. }
  2265. // lets define some options regarding the map_mode
  2266. let group_to_hit = null;
  2267. switch (this.map_mode) {
  2268. case "terraindevie":
  2269. group_to_hit = this.paper_main_object.children['entites'];
  2270. break;
  2271. case "proximite":
  2272. group_to_hit = this.paper_main_object.children['entites_proximites_references'];
  2273. break;
  2274. case "superposition":
  2275. group_to_hit = this.paper_main_object.children['entites_superposes'];
  2276. break;
  2277. case "action":
  2278. group_to_hit = this.paper_main_object.children['agissantes'];
  2279. break;
  2280. case "doleancer":
  2281. group_to_hit = this.paper_main_object.children['doleances'].children[`doleance_${this.concernement.opened_doleance.id}`];
  2282. break;
  2283. }
  2284. if (group_to_hit) {
  2285. let result = group_to_hit.hitTest(event.point);
  2286. console.log('click result', result);
  2287. if (result) {
  2288. switch (this.map_mode) {
  2289. case "terraindevie":
  2290. case "superposition":
  2291. case "action":
  2292. // we have clicked on an entite
  2293. this.$router.push({
  2294. name: 'concernement',
  2295. params: {cid: this.cid, eid: result.item.item_id},
  2296. query: {
  2297. mapitemid: this.id,
  2298. // superposition_id: this.mapitem.superposition_ids[0]
  2299. },
  2300. hash: `#${this.map_mode}`,
  2301. });
  2302. break;
  2303. case "proximite":
  2304. switch (result.item.item_type) {
  2305. case "entite_proximite":
  2306. this.$router.push({
  2307. name: 'concernement',
  2308. params: {cid: this.cid, eid: result.item.item_id},
  2309. hash: `#${this.map_mode}`,
  2310. });
  2311. break;
  2312. case "entite_proximite_reference":
  2313. this.$router.push({
  2314. name: 'concernement',
  2315. params: {cid: this.cid, eid: result.item.parent_eid},
  2316. query: {
  2317. proximite_cid: result.item.ref_cid,
  2318. proximite_eid: result.item.item_id
  2319. },
  2320. hash: `#${this.map_mode}`,
  2321. });
  2322. break;
  2323. }
  2324. case "doleancer":
  2325. this.setOpenedDoleanceField(this.cid, result.item.did, result.item.field, result.item.field_index);
  2326. break;
  2327. }
  2328. } else {
  2329. // otherwise we close the entite and come back to the concernement
  2330. this.$router.push({
  2331. name: 'concernement',
  2332. hash: `#${this.map_mode}`,
  2333. params: {id: this.cid, mapitemid: this.id}
  2334. });
  2335. // reset the mousehover
  2336. this.resetHoverElmt();
  2337. }
  2338. }
  2339. }
  2340. }.bind(this);
  2341. this.paper_main_object.onMouseDown = function(event){
  2342. console.log('onMouseDown', event);
  2343. if (this.is_open && this.map_mode === 'terraindevie' && this.concernement.can_update) {
  2344. let group_to_hit = this.paper_main_object.children['entites'];
  2345. let result = group_to_hit.hitTest(event.point);
  2346. console.log('drag result', result);
  2347. this.entite_mouse_downed = result;
  2348. }
  2349. }.bind(this);
  2350. /*
  2351. * works i correlation with updateDetailsZoomScale()
  2352. */
  2353. this.paper_main_object.onMouseDrag = async function(event){
  2354. if (this.is_open && this.map_mode === 'terraindevie' && this.concernement.can_update) {
  2355. // console.log('paper concernement onMouseDrag', event, this);
  2356. event.stopPropagation();
  2357. event.preventDefault();
  2358. if (this.entite_mouse_downed) {
  2359. // console.log('paper concernement onMouseDrag entite', this.entite_mouse_downed);
  2360. this.entite_mouse_downed.item.position.x += event.delta.x;
  2361. this.entite_mouse_downed.item.position.y += event.delta.y;
  2362. // Hide popup
  2363. this.resetHoverElmt();
  2364. // move the label
  2365. let pad = 2;
  2366. this.entite_mouse_downed.item.label_item.position.x = this.entite_mouse_downed.item.position.x + pad;
  2367. this.entite_mouse_downed.item.label_item.position.y = this.entite_mouse_downed.item.position.y - pad*2;
  2368. // indicate that the entity is been dragged (for onMouseUp)
  2369. this.entite_mouse_downed.dragged = true;
  2370. } else {
  2371. // console.log('paper concernement onMouseDrag general', event.delta);
  2372. if (this.detailsZoomValue > 1) {
  2373. let x = this.pos.x + event.delta.x;
  2374. let y = this.pos.y + event.delta.y;
  2375. this.pos = this.paper_main_object.position = this.constraint.pointA = {x: x, y: y};
  2376. Matter.Body.setPosition(this.body, this.pos);
  2377. this.is_dragging = true;
  2378. }
  2379. event.stop();
  2380. return false;
  2381. }
  2382. }
  2383. }.bind(this);
  2384. this.paper_main_object.onMouseUp = function(event){
  2385. console.log('onMouseUp', event);
  2386. if (this.is_open && this.map_mode === 'terraindevie' && this.entite_mouse_downed) {
  2387. if (this.entite_mouse_downed.dragged) {
  2388. // console.log('onMouseUp entite_mouse_downed', this.entite_mouse_downed);
  2389. this.wait = true;
  2390. let pos = {
  2391. x:this.entite_mouse_downed.item.position.x - this.pos.x,
  2392. y:this.entite_mouse_downed.item.position.y - this.pos.y
  2393. };
  2394. // compute value for api
  2395. let {af, mm, p} = this.computeNewEntitePos(pos);
  2396. // record value
  2397. let pid = this.concernement.entites_byid[this.entite_mouse_downed.item.item_id].id;
  2398. this.recordNewEntitePos(pid, af, mm, p)
  2399. .then((parag) => {
  2400. // then reload value
  2401. // redrawing entites is handle by watch concernement.entites
  2402. this.reloadConcernementEntites(this.concernement.id)
  2403. .then(() => {
  2404. this.wait = false;
  2405. });
  2406. })
  2407. }
  2408. this.entite_mouse_downed = null;
  2409. }
  2410. }.bind(this);
  2411. },
  2412. computeNewEntitePos(pos){
  2413. // actuel future
  2414. let af = pos.y >= 0 ? 0 : 1;
  2415. // menace / maintien (angle)
  2416. let mm = parseFloat(Math.atan(pos.x/Math.abs(pos.y)) * (180/Math.PI)).toFixed(2);
  2417. // Prise (rayon)
  2418. let r = Math.sqrt(Math.pow(pos.x,2)+Math.pow(pos.y,2));
  2419. // https://stackoverflow.com/questions/5731863/mapping-a-numeric-range-onto-another
  2420. // from range 0 -> rayon_de_la_boussole moins 8% de padding |to| range 0 -> 100
  2421. let ext_circle_factor = 1;//0.915; // this factor is also used in MapConcernement
  2422. let r_max = this.ray * ext_circle_factor * this.details_zoom_scale;
  2423. let r_slope = (100 - 0) / (r_max - 0);
  2424. let p = Math.max(0, 100 - parseFloat(0 + r_slope * (r - 0)).toFixed(2));
  2425. // console.log(`onMouseUp af: ${af}, mm: ${mm}, p: ${p}`);
  2426. return {af, mm, p};
  2427. },
  2428. recordNewEntitePos(pid, af, mm, p){
  2429. return new Promise((resolve, reject) => {
  2430. // record new values of entite parag (prise, actuel/future, menace/maintien)
  2431. const params = {
  2432. id: [{'value': pid}],
  2433. type: 'entite_concernement',
  2434. 'field_actuel_future': [{'value': af}],
  2435. 'field_menace_maintien_degres': [{'value': mm}],
  2436. 'field_prise': [{'value': p}]
  2437. };
  2438. const configs = {
  2439. headers: {'X-CSRF-Token': this.csrf_token}
  2440. };
  2441. // call the api
  2442. REST.patch(`/entity/paragraph/${pid}?_format=json`, params, configs)
  2443. .then(({ data }) => {
  2444. console.log('concernementMapItem REST patch parag entite', data)
  2445. resolve(data);
  2446. })
  2447. .catch(error => {
  2448. console.warn(`Issue with patch ${this.data.entitytype} ${this.data.bundle}`, error)
  2449. Promise.reject(error)
  2450. })
  2451. });
  2452. },
  2453. resetHoverElmt(){
  2454. // console.log('resetHoverElmt');
  2455. setTimeout(()=>{
  2456. this.setHoverElmt(null);
  2457. }, 100);
  2458. },
  2459. // OPEN / CLOSE (with tween)
  2460. getOpeningAvailableScale(){
  2461. // calcul opened size regarding window size and surounding contents
  2462. let header = document.querySelector('header#header');
  2463. let header_height = header.clientHeight;
  2464. let map_nav = document.querySelector('nav#map-nav');
  2465. let map_nav_height = map_nav.clientHeight;
  2466. let s_h = (this.canvas.height - header_height - map_nav_height) / (this.ray*2*1.15);
  2467. let s_w = (this.canvas.width - this.cartouch_width) / (this.ray*2*1.7);
  2468. return Math.min(s_h, s_w)
  2469. },
  2470. openClose(open) { // async
  2471. // await nextTick(); // not working
  2472. console.log(`ConcernementsMapItem openClose ${this.id} openClose: ${open}`);
  2473. if (this.tween) {
  2474. this.tween.stop();
  2475. }
  2476. if (open) {
  2477. this.is_opening = true;
  2478. // create the paper objects to display (like entite, besoin, etc)
  2479. this.setPaperContents();
  2480. this.handlePaperVisibilityOnBeforeOpen();
  2481. let s = this.getOpeningAvailableScale();
  2482. // create once the opening tweening
  2483. this.tween = new Tween.Tween({s: this.scale, x: this.pos.x, y: this.pos.y, o: 0})
  2484. .to({
  2485. s: s,
  2486. x: (this.canvas.width - this.cartouch_width) / 2,
  2487. y: this.canvas.height / 2,
  2488. o: 0.8
  2489. }, 800)
  2490. .onUpdate((obj) => {
  2491. // https://github.com/liabru/matter-js/issues/986#issuecomment-812488873
  2492. // revert to the original size (by reverting the previous scale)
  2493. // Matter.Body.scale(this.body, 1 / this.scale, 1 / this.scale)
  2494. this.paper_main_object.scale(1 / this.scale);
  2495. // then scale again to new scale
  2496. // Matter.Body.scale(this.body, obj.s, obj.s)
  2497. this.paper_main_object.scale(obj.s);
  2498. // update superposition constraints points positions
  2499. this.resetSuperpositionsConstraintsScaling(obj.s);
  2500. // record new scale
  2501. this.prev_scale = this.scale;
  2502. this.scale = this.mapitem.scale = obj.s;
  2503. this.details_zoom_scale = this.scale * this.detailsZoomValue;
  2504. this.opacity = obj.o;
  2505. // console.log('tween update obj.s', obj.s);
  2506. this.pos = {x:obj.x, y:obj.y};
  2507. Matter.Body.setPosition(this.body, this.pos);
  2508. })
  2509. .onComplete((obj) => {
  2510. // console.log('tween complete obj.s', obj.s);
  2511. // record tween one last time
  2512. this.prev_scale = this.scale = obj.s;
  2513. this.details_zoom_scale = this.scale * this.detailsZoomValue;
  2514. this.mapitem.scale = this.scale;
  2515. this.opacity = obj.o;
  2516. this.pos = {x:obj.x, y:obj.y};
  2517. Matter.Body.setPosition(this.body, this.pos);
  2518. this.handlePaperVisibilityOnOpened();
  2519. // fix the concernement position with a constraint
  2520. this.constraint = Matter.Constraint.create({
  2521. pointA: this.pos,
  2522. bodyB: this.body,
  2523. stiffness: 1,
  2524. damping: 0,
  2525. length: 0
  2526. });
  2527. Matter.Composite.add(this.matterEngine.world, [this.body, this.constraint]);
  2528. // paper bring to front
  2529. // this.paper_main_object.bringToFront();
  2530. this.paper_main_object.sendToBack();
  2531. this.is_opening = false;
  2532. });
  2533. // recreate the matter engine event to get it a the end of the events stack
  2534. Matter.Events.off(this.matterEngine, "afterUpdate", this.onAfterEngineUpdate);
  2535. Matter.Events.on(this.matterEngine, "afterUpdate", this.onAfterEngineUpdate);
  2536. } else {
  2537. this.setDetailsZoomValue(1);
  2538. this.updateDetailsZoomScale();
  2539. // CLOSING
  2540. this.is_closing = true;
  2541. if(this.constraint){
  2542. Matter.Composite.remove(this.matterEngine.world, this.constraint);
  2543. }
  2544. // this.active_revision = this.concernement.revision_id;
  2545. // this.setActiveRevision(this.cid, this.concernement.revision_id);//this.concernement.revisions[this.concernement.revisions.length -1].revision_id);
  2546. // this.resetPaperEntitesAndContours();
  2547. this.handlePaperVisibilityOnBeforeClose();
  2548. this.setOpenedEntiteId(null);
  2549. // this.setOpenedRecit(null);
  2550. // create once the closing tween
  2551. this.tween = new Tween.Tween({s: this.scale, o: 1})
  2552. .to({s: 1, o: 0}, 500)
  2553. .onUpdate((obj) => {
  2554. // https://github.com/liabru/matter-js/issues/986#issuecomment-812488873
  2555. // revert to the original size (by reverting the previous scale)
  2556. // INFO we dont need to sacle the matter body AND it may fix the montgolfière bug
  2557. // TODO find another way to increase the mass
  2558. // Matter.Body.scale(this.body, 1 / this.scale, 1 / this.scale)
  2559. this.paper_main_object.scale(1 / this.scale);
  2560. // then scale again to new scale
  2561. // Matter.Body.scale(this.body, obj.s, obj.s)
  2562. this.paper_main_object.scale(obj.s);
  2563. // update superposition constraints points positions
  2564. if (this.concernement.superposition_constraints_id
  2565. && this.concernement.superposition_constraints_id[this.id]
  2566. && this.concernement.superposition_constraints_id[this.id].length)
  2567. {
  2568. // get all the constraints of the world
  2569. let all_constrains = Matter.Composite.allConstraints(this.matterEngine.world);
  2570. // loop through all constraint ids recorded in the concernement
  2571. // get only the constraint of this concernement mapitem
  2572. for(let constraint_id of this.concernement.superposition_constraints_id[this.id]) {
  2573. // get the right constraint object from matter
  2574. let constraint;
  2575. for (const c of all_constrains) {
  2576. if (c.id === constraint_id) {
  2577. constraint = c;
  2578. break;
  2579. }
  2580. }
  2581. if (constraint) {
  2582. // tween the constraint point
  2583. let ab = this.cid === constraint.concernementA.id ? 'A' : 'B';
  2584. let point = constraint[`point${ab}`];
  2585. // revert to the original point
  2586. let oripoint = Matter.Vector.create(point.x / this.scale, point.y / this.scale)
  2587. // newpoint from original point
  2588. let newpoint = Matter.Vector.create(oripoint.x * obj.s, oripoint.y * obj.s)
  2589. constraint[`point${ab}`] = newpoint;
  2590. }
  2591. }
  2592. }
  2593. // record new scale
  2594. this.prev_scale = this.scale;
  2595. this.scale = obj.s;
  2596. this.mapitem.scale = this.scale;
  2597. this.details_zoom_scale = this.scale * this.detailsZoomValue;
  2598. this.opacity = obj.o;
  2599. })
  2600. .onComplete((obj) => {
  2601. this.prev_scale = this.scale = 1;
  2602. this.mapitem.scale = this.scale;
  2603. this.details_zoom_scale = this.scale * this.detailsZoomValue;
  2604. this.handlePaperVisibilityOnClosed();
  2605. this.clearPaperContents();
  2606. // reset the zoom value
  2607. this.setDetailsZoomValue(1);
  2608. this.is_closing = false;
  2609. });
  2610. }
  2611. this.tween.easing(Tween.Easing.Quadratic.InOut).start();
  2612. },
  2613. resetSuperpositionsConstraintsScaling(s){
  2614. if (this.concernement.superposition_constraints_id
  2615. && this.concernement.superposition_constraints_id[this.id]
  2616. && this.concernement.superposition_constraints_id[this.id].length)
  2617. {
  2618. // get all the constraints of the world
  2619. let all_constrains = Matter.Composite.allConstraints(this.matterEngine.world);
  2620. // loop through all constraint ids recorded in the concernement
  2621. // get only the constraint of this concernement mapitem
  2622. for(let constraint_id of this.concernement.superposition_constraints_id[this.id]) {
  2623. // get the right constraint object from matter
  2624. let constraint;
  2625. for (const c of all_constrains) {
  2626. if (c.id === constraint_id) {
  2627. constraint = c;
  2628. break;
  2629. }
  2630. }
  2631. if (constraint) {
  2632. // tween the constraint point
  2633. let ab = this.cid === constraint.concernementA.id ? 'A' : 'B';
  2634. let point = constraint[`point${ab}`];
  2635. // revert to the original point
  2636. let oripoint = Matter.Vector.create(point.x / this.scale, point.y / this.scale)
  2637. // newpoint from original point
  2638. let newpoint = Matter.Vector.create(oripoint.x * s, oripoint.y * s)
  2639. constraint[`point${ab}`] = newpoint;
  2640. }
  2641. }
  2642. }
  2643. },
  2644. async resetMapItemPosition(){
  2645. await nextTick();
  2646. console.log('resetMapItemPosition');
  2647. this.pos = this.paper_main_object.position = {
  2648. x: (this.canvas.width - this.cartouch_width) / 2,
  2649. y: this.canvas.height / 2
  2650. };
  2651. this.constraint.pointA = this.pos;
  2652. console.log('resetMapItemPosition', this.cartouch_width, this.pos);
  2653. Matter.Body.setPosition(this.body, this.pos);
  2654. },
  2655. async resetMapItemScale(){
  2656. await nextTick();
  2657. console.log('resetMapItemScale');
  2658. let s = this.getOpeningAvailableScale();
  2659. // revert to the original scale (by reverting the previous scale)
  2660. this.paper_main_object.scale(1 / this.scale);
  2661. // then scale again to new scale
  2662. this.paper_main_object.scale(s);
  2663. // TODO handle superposition scaling
  2664. this.resetSuperpositionsConstraintsScaling(s);
  2665. // record the new scale
  2666. this.prev_scale = this.scale = s;
  2667. this.details_zoom_scale = this.scale * this.detailsZoomValue;
  2668. },
  2669. // ENGINE UPDATE
  2670. onBeforeEngineUpdate (event) {
  2671. // update the opening/closing tweening
  2672. // if (this.tween) {
  2673. // this.tween.update();
  2674. // }
  2675. Tween.update();
  2676. if (this.opened_concernement) {
  2677. // console.log("try to push aside", this.opened_concernement.opened_mapitem_id, this.id, this.opened_concernement.superposed_mapitem_id_by_mapitem_id[this.opened_concernement.opened_mapitem_id]);
  2678. // console.log(this.id, this.opened_concernement.superposed_mapitem_id_by_mapitem_id[this.opened_concernement.opened_mapitem_id].indexOf(this.id));
  2679. if (this.opened_concernement.opened_mapitem_id !== this.id) {
  2680. // push all aside mapitems not superposed the the opened mapitem
  2681. let pushaside = true;
  2682. // BUT NOT push aside mapitems superposed to this item
  2683. // opened_mapitem <-- superposed_mapitems
  2684. if (this.map_mode === 'superposition') {
  2685. if (this.opened_concernement.superposed_mapitem_id_by_mapitem_id
  2686. && this.opened_concernement.superposed_mapitem_id_by_mapitem_id[this.opened_concernement.opened_mapitem_id])
  2687. { // if opened mapitem has superposed mapitems
  2688. let superposed_ids = this.opened_concernement.superposed_mapitem_id_by_mapitem_id[this.opened_concernement.opened_mapitem_id]
  2689. if (superposed_ids.indexOf(this.id) >= 0) { //this mapitem is directly superposed to the opened mapitem
  2690. pushaside = false;
  2691. }
  2692. }
  2693. }
  2694. if (pushaside) {
  2695. this.pushAside()
  2696. }
  2697. }
  2698. } else if (!this.is_hover){
  2699. if (this.map_mode === 'proximite'
  2700. || this.map_mode === 'superposition'
  2701. || this.map_mode === 'puissancedagir'
  2702. || this.map_mode === 'action'
  2703. || this.map_mode === 'doleancer'){ // apply focus forces : move unfocused on the sides and focused on the center
  2704. this.applyFocusForces(); //
  2705. } else {
  2706. this.applyNormalForces(); // if terrain de vie apply force to gently reject items from the sides and so create a continuasly mvmt
  2707. }
  2708. } else {
  2709. // stop movement if is mouse hover
  2710. Matter.Body.setVelocity(this.body, {x:0, y:0})
  2711. }
  2712. // reset all matter rotation forces otherwise items will spin when colide
  2713. Matter.Body.setAngle(this.body, 0);
  2714. Matter.Body.setAngularSpeed(this.body, 0);
  2715. },
  2716. applyFocusForces(){
  2717. if(!this.isFocused()) {
  2718. this.pushAside()
  2719. }else{
  2720. this.bringToCenter()
  2721. }
  2722. },
  2723. isFocused(){
  2724. return this.map_mode === 'terraindevie'
  2725. || (this.map_mode === 'proximite' && this.concernement.has_proximites)
  2726. || (this.map_mode === 'superposition' && this.concernement.has_superpositions)
  2727. || (this.map_mode === 'action' && this.concernement.has_agissantes)
  2728. || (this.map_mode === 'puissancedagir' && this.concernement.has_puissancedagir)
  2729. || (this.map_mode === 'doleancer' && this.concernement.has_doleance);
  2730. },
  2731. pushAside(){
  2732. // console.log('pushAside');
  2733. // apply a force in direction of one side or an other depending of the start position
  2734. // the force is exponentialy proportional to the distance from the side
  2735. // INFO logarithmic force : https://stackoverflow.com/questions/846221/logarithmic-slider/846249#846249
  2736. // TODO cartouch width should change regarding actual cartouch is opened or not (and how many cartouch are opened)
  2737. let pseudo_center_x = this.opened_concernement
  2738. ? (this.canvas.width - this.cartouch_width) / 2
  2739. : this.canvas.width / 2;
  2740. // get the direction to the closest side
  2741. let dir = this.map_mode === 'superposition'
  2742. && this.concernement.superposition_constraints_id
  2743. && this.concernement.superposition_constraints_id[this.id]
  2744. && this.concernement.superposition_constraints_id[this.id].length // go to the right if has superposition constraint applied
  2745. ? 1 // to the right
  2746. : this.pos.x > pseudo_center_x // else
  2747. ? 1 // to the right
  2748. : -1; // to the left
  2749. if (this.map_mode === 'doleancer') {
  2750. dir = 1;
  2751. }
  2752. // max and min item position
  2753. let minp = 0;
  2754. let maxp = dir < 0
  2755. ? pseudo_center_x
  2756. : this.canvas.width - pseudo_center_x;
  2757. // max and min force
  2758. let minf = 0;
  2759. let maxf = 6;
  2760. // scale factor
  2761. let scale = (maxf-minf) / (maxp-minp);
  2762. // get the inversed distance
  2763. let dist = dir < 0
  2764. ? this.pos.x
  2765. : this.canvas.width - this.pos.x; // get the distance from the side
  2766. // // calculate the force
  2767. // let x_force = Math.pow(dist/700,100) * dir;
  2768. // calculate the logarithmic force
  2769. let x_force = Math.exp(minf + scale*(dist-minp)) * dir;
  2770. let ori_pos = {x:pseudo_center_x, y:this.body.position.y};
  2771. Matter.Body.applyForce(
  2772. this.body,
  2773. ori_pos,
  2774. {
  2775. x: x_force,
  2776. y: 0
  2777. }
  2778. );
  2779. this.body.frictionAir = 0.01;
  2780. },
  2781. bringToCenter(){
  2782. // bring to the centre
  2783. // apply a force in direction of one side or an other depending of the start position
  2784. // the force is exponentialy inversed proportional to the distance from the side
  2785. // INFO logarithmic force : https://stackoverflow.com/questions/846221/logarithmic-slider/846249#846249
  2786. // TODO cartouch width should change regarding actual cartouch is opened or not (and how many cartouch are opened)
  2787. let pseudo_center_x = this.opened_concernement
  2788. ? (this.canvas.width - this.cartouch_width) / 2
  2789. : this.canvas.width / 2;
  2790. let dir = this.pos.x > pseudo_center_x
  2791. ? -1 // to left
  2792. : 1; // to right
  2793. // get the inversed distance from the side
  2794. let dist = dir < 0
  2795. ? this.pos.x - pseudo_center_x
  2796. : pseudo_center_x - this.pos.x;
  2797. if (dist > this.canvas.width/6) { // apply decreasing forces and increasing friction air only out of center to let the items float in the center zone
  2798. // max & min item position
  2799. let minp = 0;
  2800. let maxp = dir < 0
  2801. ? this.canvas.width - pseudo_center_x
  2802. : pseudo_center_x;
  2803. // X force decreasing near the center
  2804. // max and min force
  2805. let xminf = 0;
  2806. let xmaxf = 1;// + Math.random()*4;
  2807. // scale factor
  2808. let xscale = (xmaxf-xminf) / (maxp-minp);
  2809. let x_force = Math.exp(xminf + xscale*(dist-minp)) * dir;
  2810. let ori_pos = dir < 0
  2811. ? {x:this.canvas.width, y:this.body.position.y}
  2812. : {x:0, y:this.body.position.y};
  2813. Matter.Body.applyForce(
  2814. this.body,
  2815. ori_pos,
  2816. {
  2817. x: x_force,
  2818. y: 0
  2819. }
  2820. );
  2821. // Friction air fa (increasing near the center)
  2822. let fa_minf = 0;
  2823. let fa_maxf = 20;
  2824. // scale factor
  2825. let fa_scale = (fa_maxf-fa_minf) / (maxp-minp);
  2826. let fa = Math.exp(fa_minf + fa_scale*(dist-minp)*-1);
  2827. this.body.frictionAir = fa;
  2828. // console.log(`bringToCenter dist:${dist}, x_force:${x_force}, friction air:${fa}`);
  2829. } else { // in the ceneter zone let items floats freely
  2830. let fa = 0.01;
  2831. let velocity = Matter.Body.getVelocity(this.body);
  2832. if (velocity.x) {
  2833. let velocityx = Math.abs(velocity.x);
  2834. // map a range of numbers to another range of numbers
  2835. // INFO https://stackoverflow.com/a/46462321
  2836. let velocity_range = [50, 1000];
  2837. let fa_range = [0,3];
  2838. fa = fa_range[0] + (velocityx - velocity_range[0]) * (fa_range[1] - fa_range[0]) / (velocity_range[1] - velocity_range[0]);
  2839. // console.log(`bringToCenter velocityx:${velocityx}, fa:${fa}, velocity`, velocity);
  2840. } else {
  2841. console.warn(`bringToCenter no velocity`, velocity);
  2842. }
  2843. this.body.frictionAir = fa;
  2844. }
  2845. },
  2846. applyShuffleForces() {
  2847. // console.log('applyShuffleForces');
  2848. // var dist, dir, x_velocity;
  2849. // dir = this.pos.x > this.canvas.width/2 ? -1 : 1; // get the direction to the centre
  2850. // dist = (dir < 0 ? this.pos.x - this.canvas.width/2 : this.canvas.width/2 - this.pos.x); // get the distance from the side
  2851. // x_velocity = Math.pow(dist/650,10) * dir;
  2852. // TODO cartouch width should change regarding actual cartouch is opened or not (and how many cartouch are opened)
  2853. let pseudo_center_x = this.opened_concernement
  2854. ? (this.canvas.width - this.cartouch_width) / 2
  2855. : this.canvas.width / 2;
  2856. // get the direction to the centre
  2857. let dir = this.pos.x > pseudo_center_x
  2858. ? -1 // to left
  2859. : 1; // to right
  2860. // get the inversed distance from the side
  2861. let dist = dir < 0
  2862. ? this.pos.x - pseudo_center_x
  2863. : pseudo_center_x - this.pos.x;
  2864. dist = dist > 1000 ? 1000 : dist;
  2865. if (dist > this.canvas.width/6) { // apply decreasing forces and increasing friction air only out of center to let the items float in the center zone
  2866. // max & min item position
  2867. let minp = 0;
  2868. let maxp = dir < 0
  2869. ? this.canvas.width - pseudo_center_x
  2870. : pseudo_center_x;
  2871. // X max and min force
  2872. let xminf = 0;
  2873. // let xmaxf = 4 + Math.random()*3;
  2874. let xmaxf = 2 + Math.random()*2;
  2875. // scale factor
  2876. let xscale = (xmaxf-xminf) / (maxp-minp);
  2877. let x_velocity = Math.exp(xminf + xscale*(dist-minp))*dir;
  2878. // let y_velocity = 30 + Math.random() * 50;
  2879. // y_velocity = Math.random() > 0.5 ? -y_velocity : y_velocity;
  2880. // X max and min force
  2881. let yminf = 1;
  2882. // let ymaxf = 2 + Math.random()*4;
  2883. let ymaxf = 4 + Math.random()*2;
  2884. // scale factor
  2885. let yscale = (ymaxf-yminf) / (maxp-minp);
  2886. let y_velocity = Math.exp(yminf + yscale*(dist-minp)) * (Math.random() > 0.5 ? 1 : -1); // let ori_pos = dir < 0
  2887. // ? {x:this.canvas.width, y:this.body.position.y}
  2888. // : {x:0, y:this.body.position.y};
  2889. // let x_force = Math.pow(dist/800,10) * dir;
  2890. // console.log(`applyShuffleForces dir:${dir}, maxp:${maxp}, dist:${dist}, x_velocity:${x_velocity}, y_velocity:${y_velocity}`);
  2891. Matter.Body.setVelocity(this.body, {x: x_velocity, y: y_velocity});
  2892. } else { // if in center zone real shuffle velocity
  2893. // x_velocity = -50 + Math.random()*100;
  2894. // y_velocity = -50 + Math.random()*100;
  2895. // this.setInitBodyVelocity();
  2896. }
  2897. this.body.frictionAir = 0.01;
  2898. },
  2899. applyNormalForces () {
  2900. // bring gently to the centre
  2901. // apply a force in direction of one side or an other depending of the start position
  2902. // the force is exponentialy inversed proportional to the distance from the side
  2903. // INFO logarithmic force : https://stackoverflow.com/questions/846221/logarithmic-slider/846249#846249
  2904. // cartouch width should change regarding actual cartouch is opened or not (and how many cartouch are opened)
  2905. // TODO force is proportional to window size
  2906. // X
  2907. let pseudo_center_x = this.opened_concernement
  2908. ? (this.canvas.width - this.cartouch_width) / 2
  2909. : this.canvas.width / 2;
  2910. let xdir = this.pos.x > pseudo_center_x
  2911. ? -1 // to left
  2912. : 1; // to right
  2913. // get the inversed distance from the side
  2914. let xdist = xdir < 0
  2915. ? this.pos.x - pseudo_center_x
  2916. : pseudo_center_x - this.pos.x;
  2917. // Y
  2918. let pseudo_center_y = this.canvas.height / 2;
  2919. let ydir = this.pos.y > pseudo_center_y
  2920. ? -1 // to top
  2921. : 1; // to bottom
  2922. // get the inversed distance from the side
  2923. let ydist = ydir < 0
  2924. ? this.pos.y - pseudo_center_y
  2925. : pseudo_center_y - this.pos.y;
  2926. let k = 4;
  2927. if (xdist > this.canvas.width/k || ydist > this.canvas.height/k) { // apply decreasing forces and increasing friction air only out of center to let the items float in the center zone
  2928. // max and min force
  2929. let minf = 0;
  2930. let maxf = 0.1;
  2931. // X
  2932. // max & min item position
  2933. let xminp = 0;
  2934. let xmaxp = xdir < 0
  2935. ? this.canvas.width - pseudo_center_x
  2936. : pseudo_center_x;
  2937. // X force decrsinsing near the center
  2938. // scale factor
  2939. let xscale = (maxf-minf) / (xmaxp-xminp);
  2940. let x_force = Math.exp(minf + xscale*(xdist-xminp)) * xdir;
  2941. let xori_pos = xdir < 0
  2942. ? {x:this.canvas.width, y:this.body.position.y}
  2943. : {x:0, y:this.body.position.y};
  2944. Matter.Body.applyForce(
  2945. this.body,
  2946. xori_pos,
  2947. {
  2948. x: x_force,
  2949. y: 0
  2950. }
  2951. );
  2952. // Y
  2953. // max & min item position
  2954. let yminp = 0;
  2955. let ymaxp = ydir < 0
  2956. ? this.canvas.height - pseudo_center_y
  2957. : pseudo_center_y;
  2958. // X force decrsinsing near the center
  2959. // scale factor
  2960. let yscale = (maxf-minf) / (ymaxp-yminp);
  2961. let y_force = Math.exp(minf + yscale*(ydist-xminp)) * ydir;
  2962. let yori_pos = ydir < 0
  2963. ? {x:this.body.position.x, y:this.canvas.height}
  2964. : {x:this.body.position.x, y:0};
  2965. Matter.Body.applyForce(
  2966. this.body,
  2967. yori_pos,
  2968. {
  2969. x: 0,
  2970. y: y_force
  2971. }
  2972. );
  2973. // // Friction air fa (increasing near the center)
  2974. // let fa_minf = 0;
  2975. // let fa_maxf = 6;
  2976. // // scale factor
  2977. // let fa_scale = (fa_maxf-fa_minf) / (maxp-minp);
  2978. // let fa = Math.exp(fa_minf + fa_scale*(dist-minp)*-1);
  2979. // this.body.frictionAir = fa;
  2980. // console.log(`bringToCenter dist:${xdist}, x_force:${x_force}`);
  2981. } else { // in the ceneter zone let items floats freely
  2982. // let velocity = Matter.Body.getVelocity(this.body);
  2983. // let velocityx = Math.abs(velocity.x);
  2984. // // map a range of numbers to another range of numbers
  2985. // // INFO https://stackoverflow.com/a/46462321
  2986. // let velocity_range = [50, 1000];
  2987. // let fa_range = [0,3];
  2988. // let fa = fa_range[0] + (velocityx - velocity_range[0]) * (fa_range[1] - fa_range[0]) / (velocity_range[1] - velocity_range[0]);
  2989. // console.log(`bringToCenter velocity.x:${velocity.x}, fa:${fa}`);
  2990. // this.body.frictionAir = fa;
  2991. this.body.frictionAir = 0.1;
  2992. }
  2993. },
  2994. checkOverflow() {
  2995. // respawn element if not opened and outside screen
  2996. if (!this.is_open) {
  2997. let pad = 1;
  2998. let circleray = this.body.circleRadius+pad*1.1;
  2999. let respawn = false;
  3000. if(this.pos.x <= pad){ this.pos.x = circleray; respawn=true;}
  3001. if(this.pos.x >= this.canvas.width-pad){ this.pos.x = this.canvas.width - circleray; respawn=true;}
  3002. if(this.pos.y <= pad){ this.pos.y = circleray; respawn=true;}
  3003. if(this.pos.y >= this.canvas.height-pad){ this.pos.y = this.canvas.height - circleray; respawn=true;}
  3004. if (respawn) {
  3005. console.log('respawning');
  3006. // this.pos = respawn_pos;
  3007. Matter.Body.setPosition(this.body, {x:this.pos.x, y:this.pos.y});
  3008. // this.setInitBodyVelocity();
  3009. Matter.Body.setVelocity(this.body, {x:0,y:0});
  3010. }
  3011. }
  3012. },
  3013. onAfterEngineUpdate (event) {
  3014. this.checkOverflow();
  3015. this.paper_main_object.position = this.pos = this.body.position;
  3016. // fadein intro
  3017. // if(!this.mapitem.clone){
  3018. if (this.paper_main_object.opacity < 9) {
  3019. this.paper_main_object.opacity = this.paper_main_object.opacity * 1.1;
  3020. } else{
  3021. this.paper_main_object.opacity = 1;
  3022. }
  3023. // }
  3024. this.handlePaperVisibilityOnAfterEnginUpdate()
  3025. // DEBUG
  3026. // this.debugDrawMatterBodyCircle();
  3027. // END DEBUG
  3028. },
  3029. debugDrawMatterBodyCircle(){
  3030. if (this.paper_main_object.children['debug_circle']) {
  3031. this.paper_main_object.children['debug_circle'].remove();
  3032. }
  3033. let debugcircle = new paper.Path.Circle({
  3034. center: this.pos,
  3035. // radius: this.ray,
  3036. radius: this.body.circleRadius,
  3037. strokeColor: '#f00',
  3038. strokeWidth: 1,
  3039. name: 'debug_circle'
  3040. })
  3041. this.paper_main_object.addChild(debugcircle)
  3042. }
  3043. },
  3044. render() {
  3045. // console.log('render()', this.ctx);
  3046. },
  3047. }
  3048. </script>