ConcernementMapItem.vue 109 KB

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