1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352 |
- <script>
- import REST from '@api/rest-axios'
- import { nextTick } from 'vue'
- import Matter from "matter-js";
- import MatterAttractors from "matter-attractors";
- import paper from 'paper';
- import Tween from "@tweenjs/tween.js";
- import { mapState, mapActions } from 'pinia'
- import { ConcernementsStore } from '@/stores/concernements'
- import { CommonStore } from '@/stores/common'
- import { UserStore } from '@stores/user'
- export default {
- inject: ['canvasMap', 'matterEngine'],
- data() {
- return {
- id: null,
- cid: null,
- concernement: null,
- active_revision: null,
- entities: null,
- activeEntites: null,
- superposedEntiteID: null,
-
- canvas: null,
- ctx: null,
- pos : {
- x: 0,
- y: 0
- },
- ray: 100,
- time: 0,
- salientPoints: [],
- scale: 1,
- prev_scale: 1,
-
- entite_mouse_downed: null,
- wait: false,
-
- details_zoom_scale: 1,
- is_dragging: false,
-
- opacity: 0,
- tween: null,
- is_visible: true,
- is_open: false,
- is_opening: false,
- is_closing: false,
- is_hover: false,
-
- body: null,
- body_parts: [],
- constraint: null,
-
- paper_main_object: {},
- paper_groups: {},
-
- doleance_transition: false,
-
- paperContentsIsSet: false,
- }
- },
- props: ['mapitem'],
- computed: {
- ...mapState(ConcernementsStore,['map_mode',
- 'concernementsByID',
- 'allEntitesById',
- 'allSuperpositions_bycids',
- 'allSuperpositions_clustered',
- 'allMapItems_byid',
- 'opened_concernement',
- 'opened_entite_id',
- 'concernement_active_revision',
- 'detailsZoomValue',
- 'reloadConcernements',
- 'reloadConcernementEntites',
- 'concernements_loading_nb']),
- ...mapState(CommonStore,['hover_elmt',
- 'map_item_ray',
- 'cartouch_width',
- 'cartouch_is_opened',
- 'paper_symbol_definitions']),
- ...mapState(UserStore,['csrf_token']),
- },
- created () {
-
-
-
- this.resetConcernement();
-
-
- if(this.entites.length < 3){
- this.hideShowConcernement(this.concernement.id, false);
- }
-
-
- this.canvas = this.canvasMap.canvas
- this.ctx = this.canvasMap.ctx
-
-
- this.ray = this.map_item_ray;
-
-
- this.parseEntityPointsValues();
- let activeEntites = this.getActiveEntites(this.entites);
-
- this.sailentEntites = this.concernement.sailentEntites = this.getJarvisEnvelopeConvexeEntites(activeEntites)
-
- this.pos = this.getRandomPos();
-
- this.getSuperposedEntiteID();
-
- this.initMatterBody()
-
- this.initPaperObjects()
-
- if(this.mapitem.clone){
- if(this.map_mode === 'superposition'){
- this.handleMapitemVisibility(true);
- }else{
- this.handleMapitemVisibility(false);
- }
- }
-
-
-
- this.mapitem.scale = this.scale;
-
- },
-
-
-
-
-
- unmounted () {
-
- if(this.mapitem.clone) {
-
- paper.project.getItem({id:this.paper_main_object.id}).remove();
- };
- if (this.body) {
- Matter.Composite.remove(this.matterEngine.world, this.body);
- }
- },
- watch: {
- canvasMap: {
- handler (n, o){
-
- if (!this.canvas) {
- this.initCanvasMap()
- }
- },
- deep: true
- },
- opened_concernement: {
- handler (n, o) {
-
- if (!n) {
- this.is_open = false;
- if (this.active_revision !== this.concernement.active_revision) {
- this.active_revision = this.concernement.active_revision;
- this.resetPaperEntitesAndContours();
- }
- this.applyShuffleForces();
- } else {
- if(this.cid === n.id && this.id === n.opened_mapitem_id){
- this.is_open = this.mapitem.is_open = true;
- }else{
- this.is_open = this.mapitem.is_open = false;
- }
- }
- },
- deep: true
- },
- is_open: {
- handler (n, o) {
-
- if(n){
- this.openClose(true);
- }else if(o) {
- this.openClose(false);
- }
- },
- deep: true
- },
- map_mode: {
- handler (n, o) {
- console.log('concernementMapItem watch map_mode', o, n);
-
-
- if (n === 'terraindevie' && !this.opened_concernement) {
- this.applyShuffleForces();
- }
-
- if (this.is_open && n !== "terraindevie"){
- console.log('concernementMapItem watch map_mode CALLING setDetailsZoomValue');
- this.setDetailsZoomValue(1);
-
- this.updateDetailsZoomScale();
- }
-
-
- if (this.is_open & n !== o) {
- this.resetPaperContents();
- this.resetMapItemPosition();
- this.resetMapItemScale();
- }
-
- if(this.mapitem.clone){
- let is_visible = false;
- if(n === 'superposition'){
-
- is_visible = true;
- }else{
- if(this.opened_concernement){
- if(this.mapitem.is_open){
- is_visible = true;
- }else{
-
- let opened_mapitem_id = this.opened_concernement.opened_mapitem_id;
- if (this.opened_concernement.superposed_mapitem_id_by_mapitem_id && this.opened_concernement.superposed_mapitem_id_by_mapitem_id[opened_mapitem_id]) {
- if(this.opened_concernement.superposed_mapitem_id_by_mapitem_id[opened_mapitem_id].indexOf(this.mapitem.id) !== -1){
- is_visible = true;
- }
- }
- }
- }
- }
- this.handleMapitemVisibility(is_visible);
- }
- },
- deep: true
- },
- hover_elmt: {
- handler (n, o) {
-
- if (n && (n.type === 'concernement' || n.type === 'superposition') && n.id === this.id) {
- this.is_hover = true;
- } else {
- this.is_hover = false;
- }
- },
- deep: true
- },
- is_hover: {
- handler (n, o) {
- this.onIsHover(n);
- },
- deep: true
- },
- concernement: {
- handler (n, o){
-
-
-
-
- if(!this.concernement.parsedEntites){
- console.log(`watch mapItem ${this.cid} reseting paperentitiesandcontours`);
- this.resetPaperEntitesAndContours();
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- },
- deep: true
- },
- 'concernement.besoins': {
- handler (n, o){
-
- if (this.is_open && this.map_mode === "puissancedagir") {
-
- this.setPaperPuissanceagirBesoins(true);
- }
- },
- deep: true
- },
- 'concernement.besoins.length': {
- handler (n, o){
-
- if (this.is_open && this.map_mode === "puissancedagir" && o != null && n !== o) {
- this.resetPaperContents();
- }
- },
- deep: true
- },
-
- map_item_ray: {
- handler (n, o) {
- console.log(`map_item_ray updated o: ${o}, n: ${n}`);
- this.ray = n;
- this.updateMatterBodyRay();
- this.updatePaperObjectSize();
- },
- deep: true
- },
- concernement_active_revision: {
- handler (n, o){
-
- if (this.is_open && o) {
-
-
- if (parseInt(n.cid) === this.cid) {
- this.active_revision = n.rid;
- this.resetPaperEntitesAndContours();
- }
- }
- },
- deep: true
- },
- detailsZoomValue: {
- handler (n, o) {
- if (this.is_open && this.map_mode === "terraindevie") {
- console.log('map_item detailsZoomValue watch', n);
- this.updateDetailsZoomScale()
- }
- },
- deep: true
- },
-
-
-
-
-
-
-
- 'mapitem.concernements_loading_nb': {
- handler (n, o) {
- console.log(`ConcernementMapItem ${this.id} watch mapitem.concernements_loading_nb o, n`, o, n);
-
-
-
- this.resetConcernement();
-
- },
- deep: true
- },
- 'concernement.entites': {
- handler (n, o) {
-
-
- if (o) {
- this.resetPaperEntitesAndContours();
- this.resetPaperEntitesProximite();
- }
- },
- deep: true
- },
- wait: {
- handler (n, o){
-
-
- if (n) {
- document.body.style.cursor = "wait";
- } else {
- document.body.style.cursor = "auto";
- }
- }
- }
- },
- methods: {
- ...mapActions(CommonStore,['setHoverElmt']),
- ...mapActions(ConcernementsStore,['openCloseConcernements',
- 'hideShowConcernement',
- 'setOpenedEntiteId',
- 'setActiveRevision',
- 'setBesoinPaperId',
- 'setOpenedDoleanceField',
- 'setOpenedRecit',
- 'setDetailsZoomValue',
- ]),
- resetConcernement(){
-
- this.id = this.mapitem.id;
- this.concernement = this.concernementsByID[this.mapitem.cid];
- this.cid = this.concernement.id;
-
- this.active_revision = this.concernement.active_revision;
-
-
-
- let revisions_ids = Object.keys(this.concernement.revisions_byid);
- if (revisions_ids.indexOf(this.concernement.revision_id) !== -1) {
- this.entites = this.concernement.revisions_byid[this.concernement.revision_id].entites;
- } else {
- this.entites = this.concernement.revisions_byid[revisions_ids.pop()].entites;
- }
-
- },
- parseEntityPointsValues (){
-
-
- for (let r = 0; r < this.concernement.revisions.length; r++) {
- for (let i = 0; i < this.concernement.revisions[r].entites.length; i++) {
- let entite = this.concernement.revisions[r].entites[i]
-
-
- entite.display = {
- alpha: null,
- ray: null
- }
-
-
-
-
-
- let init_max = 100
- let slope = this.ray / init_max
- entite.display.ray = slope * (init_max - entite.prise);
-
-
-
- if (entite.actuelfuture) {
-
-
- entite.display.alpha = entite.menacemaintien + 270
- } else {
-
-
- entite.display.alpha = -1 * entite.menacemaintien + 90
- }
-
- entite.display.pos = {
- x: entite.display.ray * Math.cos(entite.display.alpha * (Math.PI/180)),
- y: entite.display.ray * Math.sin(entite.display.alpha * (Math.PI/180))
- }
-
-
-
- }
- }
- this.concernement.parsedEntites = true;
- },
- getActiveEntites(entites){
-
-
- let activeEntites = [];
- for (let i = 0; i < entites.length; i++) {
- if (entites[i].active) {
- activeEntites.push(entites[i])
- }
- }
- return activeEntites;
- },
- getSalientPoints_OLD() {
-
-
- let arc = 360/30;
-
-
- for (let i = 0; i <= 360/arc ; i++) {
-
- let max_r = 0;
- let farest = null;
- for (let j = 0; j < this.entites.length; j++) {
- let entite = this.entites[j];
- if(arc*i <= entite.display.alpha && entite.display.alpha <= arc*i+arc) {
- if (entite.display.ray > max_r) {
-
- max_r = entite.display.ray;
-
- farest = {
- alpha: entite.display.alpha,
- ray: entite.display.ray,
- pos: {
- x: (entite.display.ray + 3) * Math.cos(entite.display.alpha * (Math.PI/180)),
- y: (entite.display.ray + 3) * Math.sin(entite.display.alpha * (Math.PI/180))
- }
- };
- }
- }
- }
- if (farest) {
- this.salientPoints.push(farest)
- }
- }
-
- },
- getJarvisEnvelopeConvexeEntites(entites){
-
- if (entites.length === 0) {
- console.error('getJarvisEnvelopeConvexeEntites entites must not be empty')
- return;
- }
- let sailentEntites = [];
-
-
- let l, min_x = null;
- for (let i = 0; i < entites.length; i++) {
- let entite = entites[i];
- let x = entite.display.ray * Math.cos(entite.display.alpha * (Math.PI/180));
- if(!min_x || min_x > x){
- l = i;
- min_x = x;
- }
- }
-
-
-
- let p = l, q;
- do {
-
-
- let entite = entites[p];
- sailentEntites.push(entite);
-
-
-
-
-
-
- q = (p + 1) % entites.length;
- for (let i = 0; i < entites.length; i++) {
-
- let p_x = (entites[p].display.ray) * Math.cos(entites[p].display.alpha * (Math.PI/180));
- let p_y = (entites[p].display.ray) * Math.sin(entites[p].display.alpha * (Math.PI/180));
- let i_x = (entites[i].display.ray) * Math.cos(entites[i].display.alpha * (Math.PI/180));
- let i_y = (entites[i].display.ray) * Math.sin(entites[i].display.alpha * (Math.PI/180));
- let q_x = (entites[q].display.ray) * Math.cos(entites[q].display.alpha * (Math.PI/180));
- let q_y = (entites[q].display.ray) * Math.sin(entites[q].display.alpha * (Math.PI/180));
-
- let val = (i_y - p_y) * (q_x - i_x) - (i_x - p_x) * (q_y - i_y);
-
-
- if (val > 0){
- q = i;
- }
-
- }
-
-
-
- p = q;
- } while (p != l);
- return sailentEntites;
- },
- getRandomPos(){
- let pad = 200;
-
-
-
-
-
-
- return {
- x: pad + this.getGaussianRandom()*(this.canvas.width - pad*2),
- y: pad + this.getGaussianRandom()*(this.canvas.height - pad*2)
- };
-
- },
- getGaussianRandom(){
-
- let u = 0, v = 0;
- while(u === 0) u = Math.random();
- while(v === 0) v = Math.random();
- let num = Math.sqrt( -2.0 * Math.log( u ) ) * Math.cos( 2.0 * Math.PI * v );
- num = num / 10.0 + 0.5;
- if (num > 1 || num < 0) return this.getGaussianRandom()
- return num
- },
- getSuperposedEntiteID(){
- if (this.concernement.has_superpositions) {
- let ids = this.id.match(/(\d+)___(\d+)/i);
- if (ids) {
- let cluster_index = ids[2];
-
- for(let cid_eid of this.allSuperpositions_clustered[cluster_index] ){
- if(this.cid === cid_eid.cid){
- this.superposedEntiteID = cid_eid.eid;
- break;
- }
- }
- }
- }
- },
-
- initMatterBody (){
-
-
-
- if (!this.body) {
-
-
-
-
- MatterAttractors.Attractors.gravityConstant = -20;
-
-
- let entite_range = [3, 100];
- let ray_range = [this.ray*0.8,this.ray*1.2];
- let ray = ray_range[0] + (this.entites.length - entite_range[0]) * (ray_range[1] - ray_range[0]) / (entite_range[1] - entite_range[0]);
-
-
-
-
-
- let mass_range = [5,15];
- let mass = mass_range[0] + (this.entites.length - entite_range[0]) * (mass_range[1] - mass_range[0]) / (entite_range[1] - entite_range[0]);
-
- this.body = Matter.Bodies.circle(0, 0, ray, {
- item_type: 'concernement',
- id: this.id,
- frictionAir: 0,
- mass: mass,
- restitution: 0.06,
- collisionFilter: {
- group: -1,
- category: 0x0002,
- mask: 0x0001
- },
- plugin: {
- attractors: [
-
-
- MatterAttractors.Attractors.gravity
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ]
- }
- })
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Matter.Body.setPosition(this.body, this.pos);
-
-
-
-
-
- Matter.Composite.add(this.matterEngine.world, this.body);
-
-
- Matter.Events.on(this.matterEngine, "beforeUpdate", this.onBeforeEngineUpdate);
- Matter.Events.on(this.matterEngine, "afterUpdate", this.onAfterEngineUpdate);
- }
- },
- setInitBodyVelocity(){
- let delta = 5;
- Matter.Body.setVelocity(this.body, {
- x: -delta + Math.random()*delta*2,
- y: -delta + Math.random()*delta*2
- });
- },
- updateMatterBodyRay(){
- console.log('updateMatterBodyRay',this.ray, this.body);
- let entite_range = [3, 100];
- let ray_range = [this.ray*0.8,this.ray*1.2];
- let new_ray = ray_range[0] + (this.entites.length - entite_range[0]) * (ray_range[1] - ray_range[0]) / (entite_range[1] - entite_range[0]);
- let old_ray = this.body.circleRadius;
- let scale = new_ray/old_ray;
- Matter.Body.scale(this.body, scale, scale);
-
- console.log(`this.body circleRadius ${this.body.circleRadius}`);
- },
-
- initPaperObjects(){
-
- this.paper_main_object = new paper.Group({
- pivot: new paper.Point(this.pos),
- name: `main_${this.id}`,
- cid: this.cid,
-
- });
-
-
- this.paper_main_object.opacity = (1 + Math.random())*0.001;
-
-
- this.paper_main_object.addChild(this.setPaperContour());
- if (this.concernement.has_superpositions) {
- this.paper_main_object.addChild(this.setPaperEntitesSuperposees());
- }
- if (this.concernement.has_proximites) {
- this.paper_main_object.addChild(this.setPaperEntitesProximite());
- }
-
-
-
-
-
-
-
-
-
- this.initPaperEvents()
- },
- async updatePaperObjectSize(){
- await nextTick();
-
-
-
- if (this.is_open) {
-
-
-
- this.pos = this.paper_main_object.position = {
- x: (this.canvas.width - this.cartouch_width) / 2,
- y: this.canvas.height / 2
- };
- this.constraint.pointA = this.pos;
- Matter.Body.setPosition(this.body, this.pos);
-
-
- this.setPaperContents();
-
-
-
-
-
- }
-
-
- let clearables = ['contours'];
- clearables.forEach(child_name => {
- if (this.paper_main_object.children[child_name]) {
- this.paper_main_object.children[child_name].remove();
- }
- });
-
- this.parseEntityPointsValues()
- let activeEntites = this.getActiveEntites(this.entites);
- this.sailentEntites = this.concernement.sailentEntites = this.getJarvisEnvelopeConvexeEntites(activeEntites)
-
- this.paper_main_object.addChild(this.setPaperContour());
- },
- updateDetailsZoomScale(){
- console.log(`updateDetailsZoomScale ${this.detailsZoomValue}`);
-
- this.paper_main_object.scale(1 / this.details_zoom_scale);
-
- let prev_entite_s = 1 / this.details_zoom_scale;
-
- this.details_zoom_scale = this.scale * this.detailsZoomValue;
-
- this.paper_main_object.scale(this.details_zoom_scale);
-
- if(this.paper_main_object.children && this.paper_main_object.children['entites']){
- this.paper_main_object.children['entites'].children.forEach((child) => {
- if(child.name === 'entite'){
-
- child.scale(1 / prev_entite_s);
-
- child.scale(1 / this.details_zoom_scale);
- }else if(child.name === 'entites_labels'){
- child.opacity = -2 + this.detailsZoomValue;
- child.children.forEach((label) => {
-
- label.scale(1 / prev_entite_s);
-
- label.scale(1 / this.details_zoom_scale);
-
- })
- }
- });
- }
-
- if (this.detailsZoomValue > 1) {
- this.body.collisionFilter.mask = 0x0004;
- } else {
- this.body.collisionFilter.mask = 0x0001;
- this.resetMapItemPosition();
- }
- },
-
- setPaperContents(){
- console.log('setPaperContents');
-
-
-
- if (!this.paperContentsIsSet) {
- this.clearPaperContents();
- switch(this.map_mode){
- case 'terraindevie':
- this.addNewPaperSymbolInstance('boussole_bg', true);
- this.paper_main_object.addChild(this.setPaperEntites());
-
- break;
- case 'superposition':
- this.addNewPaperSymbolInstance('boussole_bg', true);
- break;
- case 'proximite':
- this.addNewPaperSymbolInstance('boussole_bg', true);
- this.paper_main_object.addChild(this.setPaperEntitesProximiteReferences());
- break;
- case 'puissancedagir':
- this.addNewPaperSymbolInstance('puissanceagir_bg', true);
- this.paper_main_object.addChild(this.setPaperPuissanceagirBesoins());
- break;
- case 'action':
- this.addNewPaperSymbolInstance('boussole_bg', true);
- this.paper_main_object.addChild(this.setPaperAgissantes());
- break;
- case 'doleancer':
- this.addNewPaperSymbolInstance('doleance_bg');
- this.paper_main_object.addChild(this.setPaperDoleances());
- break;
- }
- this.paperContentsIsSet = true;
- }
- },
- resetPaperContents(){
- this.paperContentsIsSet = false;
- this.setPaperContents();
- },
- resetPaperEntitesAndContours(){
- console.log(`concernementMapitem ${this.id} resetPaperEntitesAndContours this.concernement`, this.concernement);
- if (!this.isResetingPaperEntites) {
- console.log(`ResetingPaperEntites ${this.id}`);
- this.isResetingPaperEntites = true;
- this.active_revision = this.concernement.active_revision;
- console.log(`this.active_revision ${this.active_revision}`);
- console.log(`entite len : ${this.concernement.revisions_byid[this.active_revision].entites.length}`);
- this.parseEntityPointsValues()
-
- let activeEntites = this.getActiveEntites(this.concernement.revisions_byid[this.active_revision].entites);
- this.sailentEntites = this.getJarvisEnvelopeConvexeEntites(activeEntites);
-
-
- if (this.paper_main_object.children && this.paper_main_object.children.contours) {
- this.paper_main_object.children.contours.remove();
- }
-
- this.paper_main_object.addChild(this.setPaperContour());
-
-
- if (this.paper_main_object.children.entites) {
- this.paper_main_object.children.entites.remove();
- }
-
- this.paper_main_object.addChild(this.setPaperEntites());
-
- this.isResetingPaperEntites = false;
- console.log(`END ResetingPaperEntites ${this.id}`);
- }
-
- },
- clearPaperContents(){
- let clearable_children = ['boussole_bg', 'entites',
- 'entites_proximites_references',
- 'puissanceagir_bg','puissanceagir_besoins',
- 'agissantes',
- 'doleance_bg', 'doleances'];
- clearable_children.forEach(child_name => {
- if (this.paper_main_object.children[child_name]) {
- this.paper_main_object.children[child_name].remove();
- }
- });
- this.paperContentsIsSet = false;
- },
- addNewPaperSymbolInstance(name, back, scale){
- let instance = new paper.SymbolItem(this.paper_symbol_definitions[name]);
- instance.name = name;
- instance.position = this.pos;
- let s = scale ? this.scale * scale : this.scale;
- instance.scale(s);
-
- this.paper_main_object.addChild(instance);
- if (back) {
- this.paper_main_object.children[name].sendToBack();
- } else {
- this.paper_main_object.children[name].bringToFront();
- }
- },
- getPaddedRoundedSegments(points, scale){
-
- let getSegmentProps = (b,a,c) => {
- const ac = { x: c.x - a.x, y: c.y - a.y }
- const lac = Math.sqrt(Math.pow(ac.x, 2) + Math.pow(ac.y, 2));
- const ab = { x: b.x - a.x, y: b.y - a.y }
- const lab = Math.sqrt(Math.pow(ab.x, 2) + Math.pow(ab.y, 2));
- const vab = { x: ab.x/lab, y: ab.y/lab }
- const an = { x: vab.x*lac, y: vab.y*lac }
- const n = { x: a.x + an.x, y: a.y+an.y }
- const m = { x: (c.x + n.x)/2, y: (c.y + n.y)/2 }
- const ma = { x:a.x - m.x, y: a.y - m.y }
- const lma = Math.sqrt(Math.pow(ma.x, 2)+Math.pow(ma.y, 2))
- const vma = { x: ma.x/lma, y: ma.y/lma }
-
- const pad = 4;
-
- const pa = [
- a.x+vma.x*pad,
- a.y+vma.y*pad
- ]
-
- const delta = 0.05 * scale;
-
- const hli = Math.abs(lab)*delta;
- const vnai = { x: -vma.y, y: vma.x }
- const hai = [ vnai.x*hli, vnai.y*hli ];
-
- const hlo = Math.abs(lac)*delta;
- const vnao = { x: vma.y, y: -vma.x }
- const hao = [ vnao.x*hlo, vnao.y*hlo ];
- return {
- point: pa,
- handleIn: hai,
- handleOut: hao
- }
- }
- const first_point = getSegmentProps(
- points[points.length-1],
- points[0],
- points[1]
- );
- let segments = [first_point];
- for (let j = 1; j < points.length-1; j++) {
- segments.push(getSegmentProps(
- points[j-1],
- points[j],
- points[j+1]
- ))
- }
- const last_point = getSegmentProps(
- points[points.length-2],
- points[points.length-1],
- points[0]
- );
- segments.push(last_point)
- segments.push(first_point)
- return segments;
- },
- setPaperContour(){
-
-
- if (this.sailentEntites.length < 3) {
-
- let circle = new paper.Path.Circle({
- name: 'contours',
- center: this.pos,
- radius: this.ray/3,
- fillColor: 'rgba(255,255,255,0.4)',
-
- strokeColor: '#fff',
- strokeWidth: 1,
- pivot: new paper.Point(this.pos),
-
- cid: this.cid,
- })
- return circle;
- } else {
-
- let points = [];
- this.sailentEntites.forEach(entite => {
- points.push({
- x: (entite.display.ray) * Math.cos(entite.display.alpha * (Math.PI/180)),
- y: (entite.display.ray) * Math.sin(entite.display.alpha * (Math.PI/180))
- })
- })
-
- let segments = this.getPaddedRoundedSegments(points, this.scale)
-
- let paper_segments = [];
- segments.forEach(seg => {
- paper_segments.push(new paper.Segment({
- point: [this.pos.x+seg.point[0]*this.details_zoom_scale, this.pos.y+seg.point[1]*this.details_zoom_scale],
- handleIn: seg.handleIn,
- handleout: seg.handleOut
- }))
- });
-
- let contrs = new paper.Path({
- name: 'contours',
- segments: paper_segments,
- fillColor: 'rgba(255,255,255,0.4)',
-
- strokeColor: '#fff',
- strokeWidth: 1,
- pivot: new paper.Point(this.pos),
-
- cid: this.cid,
- });
-
- return contrs;
- }
-
- },
- setPaperEntites(){
- let g = new paper.Group({
- pivot: new paper.Point(this.pos),
- name: 'entites'
- });
- let g_label = new paper.Group({
- pivot: new paper.Point(this.pos),
- name: 'entites_labels',
- opacity: 0
- });
- g.addChild(g_label);
- g_label.sendToBack();
-
- for (let i = 0; i < this.concernement.revisions_byid[this.active_revision].entites.length; i++) {
- let entite = this.concernement.revisions_byid[this.active_revision].entites[i];
- if (!entite.active && !this.concernement.can_update) {
- continue;
- }
-
- let item_type = entite.entite ? entite.entite.agissante ? 'entite_action' : entite.active ? 'entite' : 'entite_inactive' : 'entite_hidden';
-
- let symbol_name = item_type;
- if(parseInt(this.opened_entite_id) === entite.entite.id){
- switch (item_type) {
- case 'entite':
- symbol_name = 'entite_hover';
- break;
- case 'inactive_entite':
- symbol_name = 'entite_inactive_hover';
- break;
- case 'entite_action':
- symbol_name = 'entite_action_hover';
- break;
- }
- }
-
- let instance = new paper.SymbolItem(this.paper_symbol_definitions[symbol_name]);
- instance.name = 'entite';
- let pos_point = new paper.Point([this.pos.x + entite.display.pos.x * this.details_zoom_scale, this.pos.y + entite.display.pos.y * this.details_zoom_scale]);
- instance.position = pos_point;
- instance.scale(this.scale);
- instance.fillColor = '#000';
- instance.item_id = entite.entite ? entite.entite.id : null;
- instance.item_type = item_type;
- instance.is_symbol_instance = true;
- g.addChild(instance);
-
- if (entite.entite && entite.entite.title) {
- let pad = 2;
- let label_pos = new paper.Point({
- x: pos_point.x + pad,
- y: pos_point.y - pad*2
- });
- let label = new paper.Group({
- pivot: pos_point,
- name: 'label',
- item_id: entite.entite ? entite.entite.id : null,
- item_type: item_type
- });
- let title = entite.entite.title;
- title = (title.length > 25) ? title.slice(0, 25 - 1) + '…' : title;
- let label_txt = new paper.PointText({
- pivot: pos_point,
- point: label_pos,
- content: title,
- fillColor: 'black',
- fontFamily: 'public_sans',
- fontSize: 3,
- justification: 'left',
- name: 'label_txt'
- })
- let b = label_txt.bounds;
- let rect = new paper.Rectangle(b.x - pad, b.y - pad, b.width + pad*2, b.height + pad*2);
- let corners = new paper.Size(1,1);
- let label_bg = new paper.Path.Rectangle(rect, corners);
- label_bg.fillColor = '#fff';
- label_bg.strokeColor = '#fff';
- label_bg.strokeWidth = 1;
- label_bg.opacity = 0.9;
- label_bg.name = 'label_bg';
- let label_click_zone = new paper.Path.Rectangle(b.x - pad, b.y - pad, b.width + pad*2, b.height + pad*2);
- label_click_zone.fillColor = '#fff';
- label_click_zone.opacity = 0;
- label_click_zone.name = 'label_click_zone';
- label_click_zone.item_id = entite.entite ? entite.entite.id : null;
- label_click_zone.item_type = item_type;
- label.addChild(label_bg);
- label_txt.insertAbove(label_bg);
- label_click_zone.insertAbove(label_txt);
-
- g_label.addChild(label);
- instance.label_item = label;
- }
- }
- return g;
- },
- setPaperEntitesSuperposees(){
-
- let g = new paper.Group({
- pivot: new paper.Point(this.pos),
- name: 'entites_superposes'
- });
- for (let i = 0; i < this.concernement.revisions_byid[this.active_revision].entites.length; i++) {
- let entite = this.concernement.revisions_byid[this.active_revision].entites[i];
- if (entite.entite
- && this.superposedEntiteID === entite.entite.id)
- {
-
-
- let instance = new paper.SymbolItem(this.paper_symbol_definitions['entite']);
- instance.name = 'entite';
- instance.position = new paper.Point([this.pos.x + entite.display.pos.x * this.scale, this.pos.y + entite.display.pos.y * this.scale]);
-
- instance.scale(3);
- instance.fillColor = '#000';
- instance.item_id = entite.entite.id;
- instance.item_type = 'entite_superpose';
- instance.is_symbol_instance = true;
- g.addChild(instance)
- break;
- }
- }
- return g;
- },
- setPaperEntitesProximite(){
- let g = new paper.Group({
- pivot: new paper.Point(this.pos),
- name: 'entites_proximites'
- });
- for (let i = 0; i < this.concernement.revisions_byid[this.active_revision].entites.length; i++) {
- let entite = this.concernement.revisions_byid[this.active_revision].entites[i];
- if (entite.entite
- && entite.entite.proximite.length )
- {
-
-
- let instance = new paper.SymbolItem(this.paper_symbol_definitions['entite']);
- instance.name = 'entite';
- instance.position = new paper.Point([this.pos.x + entite.display.pos.x * this.scale, this.pos.y + entite.display.pos.y * this.scale]);
-
- instance.scale(3);
- instance.fillColor = '#000';
- instance.item_id = entite.entite.id;
- instance.item_type = 'entite_proximite';
- instance.is_symbol_instance = true;
- g.addChild(instance)
- }
- }
- return g;
- },
- resetPaperEntitesProximite(){
- if (this.paper_main_object.children['entites_proximites']) {
- this.paper_main_object.children['entites_proximites'].remove();
- }
- if (this.concernement.has_proximites) {
- this.paper_main_object.addChild(this.setPaperEntitesProximite());
- }
- },
- setPaperEntitesProximiteReferences(){
- console.log('setPaperEntitesProximiteReferences')
- let g = new paper.Group({
- pivot: new paper.Point(this.pos),
- name: 'entites_proximites_references'
- });
-
-
- for (let i = 0; i < this.concernement.revisions_byid[this.active_revision].entites.length; i++) {
- let entite = this.concernement.revisions_byid[this.active_revision].entites[i];
- if (entite.entite
- && entite.entite.proximite.length )
- {
-
-
- let entite_pos = {
- x: this.pos.x + entite.display.pos.x * this.scale,
- y: this.pos.y + entite.display.pos.y * this.scale
- }
-
-
- let instance = new paper.SymbolItem(this.paper_symbol_definitions['entite']);
- instance.name = 'entite';
- instance.position = new paper.Point([entite_pos.x, entite_pos.y]);
-
- instance.scale(this.scale);
- instance.fillColor = '#000';
- instance.item_id = entite.entite.id;
- instance.item_type = 'entite_proximite';
- instance.is_symbol_instance = true;
- g.addChild(instance)
-
-
- let ref_g = new paper.Group({
- pivot: new paper.Point(this.pos),
- name: 'ref_entite_proximite'
- });
- let allEntiteRefConcernementContourEntites = [];
- let beta = 360 / entite.entite.proximite.length;
- let ray = 5;
- let e=0;
-
- let scaledown = 0.05;
- entite.entite.proximite.forEach(entite_ref => {
-
-
- let ref_cid = this.allEntitesById[entite_ref.id].cid;
-
- let ref_concernement = this.concernementsByID[ref_cid];
-
-
- let ref_instance = new paper.SymbolItem(this.paper_symbol_definitions['entite']);
- ref_instance.name = 'entite_ref';
- let entite_ref_pos = {
- x: entite_pos.x + ray * Math.cos((beta*e) * (Math.PI/180)) * this.scale,
- y: entite_pos.y + ray * Math.sin((beta*e) * (Math.PI/180)) * this.scale,
- }
-
-
- ref_instance.position = new paper.Point(entite_ref_pos);
-
- ref_instance.scale(this.scale*0.75);
- ref_instance.fillColor = '#000';
- ref_instance.item_id = entite_ref.id;
- ref_instance.item_type = 'entite_proximite_reference';
- ref_instance.ref_cid = ref_cid;
- ref_instance.parent_eid = entite.entite.id;
- ref_instance.is_symbol_instance = true;
- ref_g.addChild(ref_instance)
-
-
- let points = [];
- ref_concernement.sailentEntites.forEach(ent => {
- points.push({
- x: (ent.display.ray) * Math.cos(ent.display.alpha * (Math.PI/180)) * this.scale,
- y: (ent.display.ray) * Math.sin(ent.display.alpha * (Math.PI/180)) * this.scale
- })
-
-
-
- let p = {
- x: entite_ref_pos.x - entite_pos.x + (ent.display.ray * Math.cos(ent.display.alpha * (Math.PI/180))) * this.scale,
- y: entite_ref_pos.y - entite_pos.y + (ent.display.ray * Math.sin(ent.display.alpha * (Math.PI/180))) * this.scale
- }
-
-
- allEntiteRefConcernementContourEntites.push({
- display:{
- ray: Math.sqrt(Math.pow(p.x,2)+Math.pow(p.y,2)),
- alpha: parseFloat(Math.atan2(p.y,p.x) * (180/Math.PI)).toFixed(2)
- }
- })
-
- })
-
-
- let segments = this.getPaddedRoundedSegments(points, scaledown)
-
- let paper_segments = [];
- segments.forEach(seg => {
- let paddedSegPoint = {
- x: entite_ref_pos.x+seg.point[0]*scaledown,
- y: entite_ref_pos.y+seg.point[1]*scaledown
- }
-
- paper_segments.push(new paper.Segment({
- point: paddedSegPoint,
- handleIn: seg.handleIn,
- handleout: seg.handleOut
- }))
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- });
-
- const contrs = new paper.Path({
- name: 'contours',
- segments: paper_segments,
- fillColor: 'rgba(255,255,255,0.4)',
-
- strokeColor: '#fff',
- strokeWidth: 1,
- pivot: new paper.Point(this.pos),
- cid: ref_concernement.id
- });
- ref_g.addChild(contrs);
- contrs.sendToBack();
- ref_instance.contour_paper_item_id = contrs.id;
- e++;
- });
-
- let activeEntites = this.getActiveEntites(allEntiteRefConcernementContourEntites);
-
-
- let genContoursEntite = this.getJarvisEnvelopeConvexeEntites(activeEntites);
-
- let points = [];
- genContoursEntite.forEach(ent => {
- points.push({
- x: ent.display.ray * Math.cos(ent.display.alpha * (Math.PI/180)),
- y: ent.display.ray * Math.sin(ent.display.alpha * (Math.PI/180))
- })
- })
-
- let gen_scaledown = 0.16;
-
-
- let segments = this.getPaddedRoundedSegments(points, gen_scaledown)
-
- let paper_segments = [];
- segments.forEach(seg => {
- paper_segments.push(new paper.Segment({
- point: [entite_pos.x+seg.point[0]*gen_scaledown, entite_pos.y+seg.point[1]*gen_scaledown],
-
- handleIn: seg.handleIn,
- handleout: seg.handleOut
- }))
- });
-
- const genContrs = new paper.Path({
- name: 'gen_contours',
- segments: paper_segments,
- fillColor: 'rgba(255,255,255,0.4)',
-
- strokeColor: '#fff',
- strokeWidth: 1,
- pivot: new paper.Point(this.pos),
-
- });
- ref_g.addChild(genContrs);
- genContrs.sendToBack();
- g.addChild(ref_g);
- ref_g.sendToBack();
- }
- }
- return g;
- },
- setPaperAgissantes(){
- console.log('setPaperAgissantes');
- let g = new paper.Group({
- pivot: new paper.Point(this.pos),
- name: 'agissantes'
- });
-
- for (let i = 0; i < this.concernement.revisions_byid[this.concernement.revision_id].entites.length; i++) {
- let entite = this.concernement.revisions_byid[this.concernement.revision_id].entites[i];
-
- if (entite.entite && entite.entite.agissante) {
- let instance = new paper.SymbolItem(this.paper_symbol_definitions['entite_action']);
- instance.name = 'entite_action';
- instance.position = new paper.Point([this.pos.x + entite.display.pos.x * this.scale, this.pos.y + entite.display.pos.y * this.scale]);
- instance.fillColor = '#000';
-
- instance.scale(this.scale);
- instance.item_id = entite.entite.id;
- instance.item_type = 'entite_action';
- instance.is_symbol_instance = true;
- g.addChild(instance)
- }
- }
- return g;
- },
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- setPaperPuissanceagirBesoins(update){
- console.log(`setPaperPuissanceagirBesoins cid:${this.concernement.id}, update: ${update}`);
- let g;
- if (update) {
- g = this.paper_main_object.children['puissanceagir_besoins'];
- console.log('REUSING puissanceagir_besoins group', g);
- } else{
- console.log('CREATING puissanceagir_besoins group');
- g = new paper.Group({
- pivot: new paper.Point(this.pos),
- name: 'puissanceagir_besoins'
- });
- }
- if (!g) {
- console.warn('no puissanceagir_besoins group created nor found')
- return;
- }
- let res_fields = ['qui','quoi','ou','avec'];
- let arc = (360 / 16);
- let r = (this.ray * this.scale)/5;
- let br = r - r/3;
- for (let i = 0; i < this.concernement.besoins.length; i++) {
- let start_a = arc * i;
- let center_a = start_a + arc/2;
- let x = Math.cos(center_a*(Math.PI/180)) * br;
- let y = Math.sin(center_a*(Math.PI/180)) * br;
-
- let paper_besoin;
- if (update) {
- paper_besoin = this.paper_main_object.getItem({id: this.concernement.besoins[i].paper_id});
-
- } else{
-
- paper_besoin = new paper.SymbolItem(this.paper_symbol_definitions['besoin']);
- paper_besoin.scale(this.scale);
- paper_besoin.item_id = this.concernement.besoins[i].id;
- paper_besoin.item_cid = this.concernement.id;
- paper_besoin.item_type = 'besoin';
- paper_besoin.is_symbol_instance = true;
- g.addChild(paper_besoin)
-
- this.setBesoinPaperId(paper_besoin.id, this.cid, this.concernement.besoins[i].id);
- }
- console.log(`paper paper_besoin id:${paper_besoin.id}`);
-
- if (!paper_besoin) {
- console.warn('no paper_besoin item created nor found')
- return;
- }
- paper_besoin.position = new paper.Point([this.pos.x + x, this.pos.y + y]);
- let res_arc = arc / (1 + this.concernement.besoins[i].reponses.length);
- for (let j = 0; j < this.concernement.besoins[i].reponses.length; j++) {
- let res_a = start_a + res_arc * (j+1);
- for (let f = 0; f < res_fields.length; f++) {
- if( this.concernement.besoins[i].reponses[j][res_fields[f]]
- && (f === res_fields.length -1 || !this.concernement.besoins[i].reponses[j][res_fields[f+1]])
- ){
- let rr = this.ray * this.scale - r*f - r/2;
- let rx = Math.cos(res_a*(Math.PI/180)) * rr;
- let ry = Math.sin(res_a*(Math.PI/180)) * rr;
-
- let paper_reponse;
- let paper_reponse_id = this.concernement.besoins[i].reponses[j].paper_id;
- if (update && paper_reponse_id) {
-
- paper_reponse = this.paper_main_object.getItem({id: paper_reponse_id});
-
- } else {
-
-
- paper_reponse = new paper.SymbolItem(this.paper_symbol_definitions['reponse']);
- paper_reponse.scale(this.scale);
- paper_reponse.item_id = this.concernement.besoins[i].reponses[j].id;
- paper_reponse.item_bid = this.concernement.besoins[i].id;
- paper_reponse.item_cid = this.concernement.id;
- paper_reponse.item_type = 'reponse';
- paper_reponse.is_symbol_instance = true;
- this.setBesoinPaperId(paper_reponse.id, this.cid, this.concernement.besoins[i].id, this.concernement.besoins[i].reponses[j].id);
- g.addChild(paper_reponse);
- }
- if (!paper_reponse) {
- console.warn('no paper_reponse item created nor found')
- return;
- }
- paper_reponse.position = new paper.Point([this.pos.x + rx, this.pos.y + ry]);
- }
- }
- }
- }
- return g;
- },
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- setPaperDoleances(){
- let g = new paper.Group({
- pivot: new paper.Point({x:0,y:0}),
- name: `doleances`
- });
- this.concernement.doleances.forEach((d) => {
- g.addChild(this.setPaperDoleanceSteps(d))
- });
- return g;
- },
- setPaperDoleanceSteps(doleance){
- let g = new paper.Group({
- pivot: new paper.Point({x:0,y:0}),
- name: `doleance_${doleance.id}`,
- doleance_id: doleance.id,
- visible: false
- });
-
- let all_fields = [
- [
- 'leprobleme',
- 'lenquete',
- {
- fieldname: 'groupesinterets',
- fields: [
- 'groupe_interets',
- 'accorder_interets',
- 'formuler',
- ]
- }
- ],
- [
- 'entite_addresse_doleance',
- 'comment_ennonce_doleance',
- 'aqui_addresse_doleance',
- {
- fieldname: 'reception_traitement',
- fields: [
- 'entite_adressee',
- 'doleance_formulee',
- 'traite_doleance',
- 'entite_recoit_doleance',
- ]
- }
- ],
- [
- 'entites_decisionnaires',
- 'decision_formule',
- {
- fieldname: 'mise_en_oeuvre_decision',
- fields: [
- 'entite_adresse_decision',
- 'formule_decision',
- 'entite_metenoeuvre_decisio',
- ]
- }
- ],
- [
- 'entite_adresse_application',
- 'aqui_adresse_decision',
- 'comment_formule_decision',
- {
- fieldname: 'receptions_et_applications',
- fields: [
- 'applique_decision',
- 'formule_decision_applic',
- 'entite_recoit_decision',
- ]
- },
- 'probleme_initial_resolu',
- 'oui_nouvelle_situation',
- 'non_adresse_doleance',
- ]
- ];
-
- var r = this.ray * this.scale * 0.8;
- var dr = r/2;
-
-
-
-
-
-
- let m = Math.sin(45*(Math.PI/180)) * r;
- let n = Math.sin(45*(Math.PI/180)) * r/2;
- let o = Math.cos(22.5*(Math.PI/180)) * r;
- let p = Math.sin(22.5*(Math.PI/180)) * r;
- let o_d = Math.cos(22.5*(Math.PI/180)) * r/2;
- let p_d = Math.sin(22.5*(Math.PI/180)) * r/2;
- let step_Style = {
- strokeColor: '#fff',
- strokeWidth: 2,
- fillColor: "rgba(255, 255, 255, 0.3)"
- }
-
-
-
-
-
-
-
-
- if (doleance.lenquete) {
- let cam = new paper.Path({...step_Style, ...{
- item_type: 'doleance_step',
- item_id: `lenquete`,
- did: doleance.id,
- field: 'lenquete',
- field_index: null
- }
- });
- cam.add({x: this.pos.x , y: this.pos.y + dr});
- cam.lineTo({x: this.pos.x, y: this.pos.y + r});
- cam.arcTo({x: this.pos.x - p, y: this.pos.y + o}, {x: this.pos.x - m, y: this.pos.y + m});
- cam.lineTo({x: this.pos.x - n, y: this.pos.y + n});
- cam.arcTo({x: this.pos.x - p_d, y: this.pos.y + o_d}, {x: this.pos.x , y: this.pos.y + dr});
-
-
-
-
-
-
-
-
-
-
-
-
- g.addChild(cam);
- }
-
-
-
-
-
-
- if(doleance.probleme_initial_resolu === 0 || doleance.probleme_initial_resolu === 1){
- let rescam = new paper.Path({...step_Style, ...{
- closed: true,
- item_type: 'doleance_step',
- item_id: `probleme_initial_resolu`,
- did: doleance.id,
- field: 'probleme_initial_resolu',
- field_index: null
- }
- });
- rescam.add({x: this.pos.x + n, y: this.pos.y + n});
- rescam.lineTo({x: this.pos.x + m , y: this.pos.y + m});
- rescam.arcTo({x: this.pos.x + p, y: this.pos.y + o}, {x: this.pos.x, y: this.pos.y + r});
- rescam.lineTo({x: this.pos.x, y: this.pos.y + dr});
- rescam.arcTo({x: this.pos.x + p_d, y: this.pos.y + o_d}, {x: this.pos.x + n, y: this.pos.y + n});
-
-
-
-
-
-
-
-
-
-
-
- g.addChild(rescam)
- }
-
-
-
-
-
- let multiple_fields = [
- { field_name: 'groupesinterets', arc: 45, decalage: -45 },
- { field_name: 'reception_traitement', arc: 90, decalage: -90 },
- { field_name: 'mise_en_oeuvre_decision', arc: 90, decalage: -180 },
- { field_name: 'receptions_et_applications', arc: 45, decalage: 90 }
- ]
- multiple_fields.forEach((mf, j) => {
- for (let i = 0, l = doleance[mf.field_name].length, a = mf.arc/l; i < l; i++) {
-
-
-
-
-
-
-
- let x1= this.pos.x + Math.sin((mf.decalage- a*i)*(Math.PI/180)) * dr,
- y1= this.pos.y + Math.cos((mf.decalage- a*i)*(Math.PI/180)) * dr;
- let x2= this.pos.x + Math.sin((mf.decalage- a*i)*(Math.PI/180)) * r,
- y2= this.pos.y + Math.cos((mf.decalage- a*i)*(Math.PI/180)) * r;
- let x3= this.pos.x + Math.sin((mf.decalage- a*(i+1))*(Math.PI/180)) * r,
- y3= this.pos.y + Math.cos((mf.decalage- a*(i+1))*(Math.PI/180)) * r;
- let x3t= this.pos.x + Math.sin((mf.decalage- a*(i+0.5))*(Math.PI/180)) * r,
- y3t= this.pos.y + Math.cos((mf.decalage- a*(i+0.5))*(Math.PI/180)) * r;
- let x4= this.pos.x + Math.sin((mf.decalage- a*(i+1))*(Math.PI/180)) * dr,
- y4= this.pos.y + Math.cos((mf.decalage- a*(i+1))*(Math.PI/180)) * dr;
- let x4t= this.pos.x + Math.sin((mf.decalage- a*(i+0.5))*(Math.PI/180)) * dr,
- y4t= this.pos.y + Math.cos((mf.decalage- a*(i+0.5))*(Math.PI/180)) * dr;
- let x5= this.pos.x + Math.sin((mf.decalage- a*(i+0.5))*(Math.PI/180)) * r*0.75,
- y5= this.pos.y + Math.cos((mf.decalage- a*(i+0.5))*(Math.PI/180)) * r*0.75;
- let p = new paper.Path({...step_Style, ...{
- item_type: 'doleance_step',
- item_id: `${mf.field_name}-${i}`,
- did: doleance.id,
- field: mf.field_name,
- field_index: i
- }
- });
- p.add([x1,y1]);
- p.lineTo([x2,y2]);
- p.arcTo([x3t,y3t], [x3,y3]);
- p.lineTo([x4,y4]);
- p.arcTo([x4t,y4t], [x1,y1]);
- g.addChild(p);
-
-
-
-
-
-
-
-
-
-
- }
- });
-
- let cardinal_Style = {
- strokeColor: '#fff',
- strokeWidth: 2,
- fillColor: "rgba(255, 255, 255, 0.9)"
- }
-
- if (doleance.leprobleme) {
- g.addChild(new paper.Path.Circle({
- center: [this.pos.x, this.pos.y + r],
- radius: 3 * this.scale,
- style: cardinal_Style,
- item_type: 'doleance_step',
- item_id: `leprobleme`,
- did: doleance.id,
- field: 'leprobleme'
- }));
- }
-
-
- if (doleance.entite_addresse_doleance || doleance.aqui_addresse_doleance || doleance.comment_ennonce_doleance) {
- g.addChild(new paper.Path.Circle({
- center: [this.pos.x - r, this.pos.y],
- radius: 3 * this.scale,
- style: cardinal_Style,
- item_type: 'doleance_step',
- item_id: `adresse_de_la_doleance`,
- did: doleance.id,
- field: 'adresse_de_la_doleance'
- }));
- }
-
-
-
- if (doleance.entites_decisionnaires || doleance.decision_formule) {
- g.addChild(new paper.Path.Circle({
- center: [this.pos.x, this.pos.y - r],
- radius: 3 * this.scale,
- style: cardinal_Style,
- item_type: 'doleance_step',
- item_id: `decision`,
- did: doleance.id,
- field: 'decision'
- }));
- }
-
- if (doleance.entite_adresse_application || doleance.aqui_adresse_decision || doleance.comment_formule_decision) {
- g.addChild(new paper.Path.Circle({
- center: [this.pos.x + r, this.pos.y],
- radius: 3 * this.scale,
- style: cardinal_Style,
- item_type: 'doleance_step',
- item_id: `adresse_de_la_decision`,
- did: doleance.id,
- field: 'adresse_de_la_decision'
- }));
- }
-
- return g;
- },
-
- handleMapitemVisibility(state){
- this.is_visible = state;
- this.paper_main_object.visible = this.is_visible;
- },
-
- handlePaperVisibilityOnBeforeOpen(){
-
-
-
-
-
-
-
-
-
-
- let entites_superposes = this.paper_main_object.children['entites_superposes'];
- if(entites_superposes){
- for(let paper_item of entites_superposes.children) {
- paper_item.scale(0.25)
- }
- }
-
-
- let entites_proximites = this.paper_main_object.children['entites_proximites'];
- if(entites_proximites){
- for(let paper_item of entites_proximites.children) {
- paper_item.scale(0.25)
- }
- }
- },
- handlePaperVisibilityOnOpened(){},
- handlePaperVisibilityOnBeforeClose(){
-
-
- let entites_superposes = this.paper_main_object.children['entites_superposes'];
- if(entites_superposes){
- for(let paper_item of entites_superposes.children) {
- paper_item.scale(4)
- }
- }
-
-
- let entites_proximites = this.paper_main_object.children['entites_proximites'];
- if(entites_proximites){
- for(let paper_item of entites_proximites.children) {
- paper_item.scale(4)
- }
- }
- },
- handlePaperVisibilityOnClosed(){
-
-
-
-
-
-
-
-
- },
- handlePaperVisibilityOnAfterEnginUpdate(){
-
- let fc, sc, sw;
- if (!this.isFocused()){
- fc = "rgba(255,255,255,0.1)";
- }else{
- fc = "rgba(255,255,255,0.4)";
- if (this.concernement.can_update) {
- sc = "#01ffe2";
- if (this.is_hover) {
- sw = 2;
- }else{
- sw = 1;
- }
- } else {
- if (this.is_hover) {
- sc = "#01ffe2";
- sw = 2;
- }else{
- sc = "#fff";
- sw = 1;
- }
- }
- }
- this.paper_main_object.children['contours'].fillColor = fc
- this.paper_main_object.children['contours'].strokeColor = sc;
- this.paper_main_object.children['contours'].strokeWidth = sw;
-
- if (!this.is_open
- || (this.is_open && this.map_mode !== "puissancedagir" && this.map_mode !== "doleancer")) {
- this.paper_main_object.children['contours'].visible = true;
- } else {
- this.paper_main_object.children['contours'].visible = false;
- }
-
- if (this.concernement.has_proximites) {
- if (this.map_mode === "proximite") {
- this.paper_main_object.children.entites_proximites.visible = true;
- }else{
- this.paper_main_object.children.entites_proximites.visible = false;
- }
- }
-
- if (this.concernement.has_superpositions) {
- if (this.map_mode === "superposition") {
- this.paper_main_object.children.entites_superposes.visible = true;
-
- let group = this.paper_main_object.children['entites_superposes'];
- if(group){
- if (this.$route.query.superposition_id) {
- let superposition_id = this.$route.query.superposition_id;
- if(superposition_id){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- }else{
- group.children.forEach((item) => {
- if(!this.is_hover) {
- item.definition = this.paper_symbol_definitions.entite;
- if (item.focused) {
- item.scale(0.5)
- item.focused = false;
- }
- }
- })
- }
- }
- } else {
- this.paper_main_object.children.entites_superposes.visible = false;
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if (this.concernement.has_doleance) {
- if (this.map_mode === "doleancer") {
- if (!this.is_open) {
-
- } else {
-
-
- let from = null
- let to = this.concernement.opened_doleance.id;
-
- this.concernement.doleances.forEach((d) => {
-
- if (this.paper_main_object.children.doleances.children[`doleance_${d.id}`].visible) {
- from = d.id
- }
- })
-
- if (from && from !== to) {
- this.initDoleanceTransition(from, to);
- } else if(!this.doleance_transition) {
- this.concernement.doleances.forEach((d) => {
- this.paper_main_object.children.doleances.children[`doleance_${d.id}`].visible = d.id === this.concernement.opened_doleance.id;
- })
- }
- }
- } else {
-
-
- }
- }
-
-
- if (this.is_open && (this.map_mode === 'terraindevie' || this.map_mode === 'action')) {
- let group = this.map_mode === 'terraindevie' ? this.paper_main_object.children['entites'] : this.paper_main_object.children['agissantes'];
- if(group){
- group.children.forEach((item) => {
- if (this.opened_entite_id && item.item_id === parseInt(this.opened_entite_id) && item.item_type !== 'entite_hidden') {
-
- item.definition = item.item_type === 'entite' ? this.paper_symbol_definitions.entite_hover
- : item.item_type === 'entite_inactive' ? this.paper_symbol_definitions.entite_inactive_hover
- : this.paper_symbol_definitions.entite_action_hover;
- } else {
-
- if ((!this.hover_elmt || item.item_id !== this.hover_elmt.id) && item.item_type !== 'entite_hidden') {
- item.definition = item.item_type === 'entite' ? this.paper_symbol_definitions.entite
- : item.item_type === 'entite_inactive' ? this.paper_symbol_definitions.entite_inactive
- : this.paper_symbol_definitions.entite_action;
- }
- }
- })
- }
- let labels_group = this.paper_main_object.children['entites'].children['entites_labels'];
- if (labels_group) {
- labels_group.children.forEach((item) => {
- if (this.opened_entite_id && item.item_id === parseInt(this.opened_entite_id) && item.item_type !== 'entite_hidden') {
- item.bringToFront();
- item.children[0].strokeColor = "#01ffe2";
- }else{
-
- }
- })
- }
- }
-
- },
- initDoleanceTransition(from, to){
- if (!this.doleance_transition) {
- this.doleance_transition = true
-
- let from_pg = this.paper_main_object.children.doleances.children[`doleance_${from}`]
- from_pg.visible = true;
- from_pg.opacity = 1;
- let to_pg = this.paper_main_object.children.doleances.children[`doleance_${to}`]
- to_pg.visible = true;
- to_pg.opacity = 0;
- let bg = this.paper_main_object.children.doleance_bg;
-
-
- new Tween.Tween({o: 1})
- .to({
- o: 0
- }, 600)
- .onUpdate((obj) => {
- console.log(`tween update. o=${obj.o}`);
- from_pg.opacity = bg.opacity = obj.o;
- })
- .onComplete((obj) => {
- new Tween.Tween({o: 0})
- .to({
- o: 1
- }, 900)
- .onUpdate((objb) => {
- to_pg.opacity = bg.opacity = objb.o;
- })
- .onComplete((obj) => {
- from_pg.visible = false;
- from_pg.opacity = 1;
- to_pg.opacity = 1;
- this.doleance_transition = false
- })
- .delay(500)
- .easing(Tween.Easing.Quadratic.InOut)
- .start();
- })
- .easing(Tween.Easing.Quadratic.Out)
- .start();
-
-
- }
- },
- onIsHover(){
-
- if (this.is_hover) {
- this.paper_main_object.bringToFront();
- } else {
-
-
- if (!this.opened_concernement) {
- this.paper_main_object.sendToBack();
- }
- }
-
- let entites_superposes = this.paper_main_object.children['entites_superposes'];
-
- if(entites_superposes){
- for(let paper_item of entites_superposes.children) {
- if (this.is_hover) {
- paper_item.definition = this.paper_symbol_definitions.entite_hover;
-
- } else {
- paper_item.definition = this.paper_symbol_definitions.entite;
-
- }
- }
- }
- },
-
- initPaperEvents(){
- this.paper_main_object.onMouseLeave = function(event){
- if (this.wait) {
-
-
- document.body.style.cursor = "wait";
- } else {
- if (!this.opened_concernement && this.isFocused()) {
- this.resetHoverElmt();
- document.body.style.cursor = "auto";
- }
- if (this.is_open) {
- document.body.style.cursor = "auto";
- }
-
- }
- }.bind(this);
- this.paper_main_object.onMouseMove = function(event){
-
-
- if (this.cartouch_is_opened && this.map_mode !== "superposition") return;
-
- if (!this.is_open) {
- if (!this.opened_concernement) {
- if(this.isFocused()){
- if (this.map_mode === 'superposition') {
-
- this.setHoverElmt({
- type: 'superposition',
- id: this.id,
- cid: this.cid,
- eid: this.superposedEntiteID
- });
- } else{
- this.setHoverElmt({
- type: 'concernement',
- id: this.id,
- cid: this.cid
- });
- }
- document.body.style.cursor = "pointer";
- }
- } else if (this.map_mode === 'superposition'){
-
- if(this.opened_concernement.all_superposed_concernements_id.indexOf(this.cid) >= 0){
- this.setHoverElmt({
- type: 'superposition',
- id: this.id,
- cid: this.cid,
- eid: this.superposedEntiteID
- });
- document.body.style.cursor = "pointer";
- }
- }
- } else {
-
-
- if (this.paper_main_object.children['entites_proximites_references']) {
- this.paper_main_object.children['entites_proximites_references'].getItems({name:'contours'}).forEach((contr) => {
- contr.strokeColor = '#fff';
- })
- }
-
- if (this.paper_main_object.children['entites'] && this.paper_main_object.children['entites'].children['entites_labels']) {
- this.paper_main_object.children['entites'].children['entites_labels'].children.forEach((label) => {
- if (!this.opened_entite_id || label.item_id != parseInt(this.opened_entite_id)) {
- label.children['label_bg'].strokeColor = '#fff';
- }
-
- })
- }
-
- let paper_group_tohit;
- switch (this.map_mode) {
- case "terraindevie":
- paper_group_tohit = this.paper_main_object.children['entites'];
- break;
- case "proximite":
- paper_group_tohit = this.paper_main_object.children['entites_proximites_references'];
- break;
- case "superposition":
- paper_group_tohit = this.paper_main_object.children['entites_superposes'];
- break;
- case "action":
- paper_group_tohit = this.paper_main_object.children['agissantes'];
- break;
- case "puissancedagir":
- paper_group_tohit = this.paper_main_object.children['puissanceagir_besoins'];
- break;
- case "doleancer":
- if(this.paper_main_object.children['doleances']){
- paper_group_tohit = this.paper_main_object.children['doleances'].children[`doleance_${this.concernement.opened_doleance.id}`];
- }
- break;
- }
- let result = paper_group_tohit ? paper_group_tohit.hitTest(event.point) : null;
-
- if (this.wait) {
-
-
- document.body.style.cursor = "wait";
- } else if (result && result.item.item_id && (result.item.name != "label_click_zone" || this.detailsZoomValue > 2)) {
-
- let new_hover_elmt = {
- paper_id: result.item.id,
- type: result.item.item_type,
- id: result.item.item_id
- };
- switch (result.item.item_type) {
- case "entite_proximite_reference":
- new_hover_elmt.ref_cid = result.item.ref_cid;
- new_hover_elmt.parent_eid = result.item.parent_eid;
-
-
- let contrs_paper_id = result.item.contour_paper_item_id;
- let contrs_paper_obj = result.item.parent.getItem({id: contrs_paper_id});
- contrs_paper_obj.strokeColor = "#01ffe2";
- break;
- case "besoin":
- new_hover_elmt.no_popup = true;
- break;
- case "reponse":
- new_hover_elmt.bid = result.item.item_bid;
- new_hover_elmt.cid = result.item.item_cid;
- new_hover_elmt.no_popup = true;
- break;
- case "entite":
- case "entite_action":
- if(result.item.name == "label_click_zone"){
-
- result.item.parent.bringToFront();
- result.item.parent.children[0].strokeColor = "#01ffe2";
- }
- break;
- }
- if (!this.hover_elmt || new_hover_elmt.paper_id !== this.hover_elmt.paper_id) {
-
- if (this.detailsZoomValue <= 2) {
- this.setHoverElmt(new_hover_elmt);
- }
- }
- document.body.style.cursor = "pointer";
-
- } else {
-
- this.resetHoverElmt();
- if (this.detailsZoomValue > 1) {
- document.body.style.cursor = "grab";
- } else {
- document.body.style.cursor = "auto";
- }
- }
- }
- }.bind(this);
-
- this.paper_main_object.onClick = async function(event){
- console.log('paper concernement onClick');
-
-
- if (this.cartouch_is_opened) return;
-
- if (!this.is_open) {
- console.log('mapitem is NOT opened');
- if (!this.opened_concernement) {
- console.log(`Open me ${this.id}`);
-
-
- let params = {cid: parseInt(this.cid)}
-
- let query = {mapitemid: this.id};
- if (this.map_mode === "superposition") {
- params.eid = this.superposedEntiteID
- query.superposition_cluster_index = this.mapitem.superposition_cluster_index;
- }
- await this.$router.push({
- name: 'concernement',
- params: params,
- query: query,
- hash: `#${this.map_mode}`
- });
-
- this.openCloseConcernements(this.cid, this.id)
-
- this.resetHoverElmt();
- } else if (this.map_mode === 'superposition'){
-
- if(this.opened_concernement.all_superposed_concernements_id.indexOf(this.cid) >= 0){
-
-
- console.log('click on superposed this.mapitem.superposition_cluster_index', this.mapitem.superposition_cluster_index);
- await this.$router.push({
- name: 'concernement',
- params: {cid: this.opened_concernement.cid, eid: this.$route.params.eid},
- query: {
- mapitemid: this.opened_concernement.opened_mapitem_id,
- superposition_cluster_index: this.mapitem.superposition_cluster_index,
- superposed_cid: this.cid
- },
- hash: `#${this.map_mode}`
- });
- }
- }
- } else {
- console.log('mapitem is opened');
-
- if (this.is_dragging) {
- this.is_dragging = false;
- return;
- }
-
- let group_to_hit = null;
- switch (this.map_mode) {
- case "terraindevie":
- group_to_hit = this.paper_main_object.children['entites'];
- break;
- case "proximite":
- group_to_hit = this.paper_main_object.children['entites_proximites_references'];
- break;
- case "superposition":
- group_to_hit = this.paper_main_object.children['entites_superposes'];
- break;
- case "action":
- group_to_hit = this.paper_main_object.children['agissantes'];
- break;
- case "doleancer":
- group_to_hit = this.paper_main_object.children['doleances'].children[`doleance_${this.concernement.opened_doleance.id}`];
- break;
- }
- if (group_to_hit) {
- let result = group_to_hit.hitTest(event.point);
- console.log('click result', result);
- if (result) {
- switch (this.map_mode) {
- case "terraindevie":
- case "superposition":
- case "action":
-
- this.$router.push({
- name: 'concernement',
- params: {cid: this.cid, eid: result.item.item_id},
- query: {
- mapitemid: this.id,
-
- },
- hash: `#${this.map_mode}`,
- });
- break;
- case "proximite":
- switch (result.item.item_type) {
- case "entite_proximite":
- this.$router.push({
- name: 'concernement',
- params: {cid: this.cid, eid: result.item.item_id},
- hash: `#${this.map_mode}`,
- });
- break;
- case "entite_proximite_reference":
- this.$router.push({
- name: 'concernement',
- params: {cid: this.cid, eid: result.item.parent_eid},
- query: {
- proximite_cid: result.item.ref_cid,
- proximite_eid: result.item.item_id
- },
- hash: `#${this.map_mode}`,
- });
- break;
- }
-
- case "doleancer":
- this.setOpenedDoleanceField(this.cid, result.item.did, result.item.field, result.item.field_index);
- break;
- }
-
- } else {
-
- this.$router.push({
- name: 'concernement',
- hash: `#${this.map_mode}`,
- params: {id: this.cid, mapitemid: this.id}
- });
-
- this.resetHoverElmt();
- }
- }
- }
- }.bind(this);
- this.paper_main_object.onMouseDown = function(event){
- console.log('onMouseDown', event);
- if (this.is_open && this.map_mode === 'terraindevie' && this.concernement.can_update) {
- let group_to_hit = this.paper_main_object.children['entites'];
- let result = group_to_hit.hitTest(event.point);
- console.log('drag result', result);
- this.entite_mouse_downed = result;
- }
- }.bind(this);
-
- this.paper_main_object.onMouseDrag = async function(event){
- if (this.is_open && this.map_mode === 'terraindevie' && this.concernement.can_update) {
-
- event.stopPropagation();
- event.preventDefault();
-
-
- if (this.entite_mouse_downed) {
-
- this.entite_mouse_downed.item.position.x += event.delta.x;
- this.entite_mouse_downed.item.position.y += event.delta.y;
-
-
- this.resetHoverElmt();
-
- let pad = 2;
- this.entite_mouse_downed.item.label_item.position.x = this.entite_mouse_downed.item.position.x + pad;
- this.entite_mouse_downed.item.label_item.position.y = this.entite_mouse_downed.item.position.y - pad*2;
-
- this.entite_mouse_downed.dragged = true;
- } else {
-
- if (this.detailsZoomValue > 1) {
- let x = this.pos.x + event.delta.x;
- let y = this.pos.y + event.delta.y;
-
- this.pos = this.paper_main_object.position = this.constraint.pointA = {x: x, y: y};
- Matter.Body.setPosition(this.body, this.pos);
-
- this.is_dragging = true;
- }
- event.stop();
- return false;
- }
- }
- }.bind(this);
-
- this.paper_main_object.onMouseUp = function(event){
- console.log('onMouseUp', event);
- if (this.is_open && this.map_mode === 'terraindevie' && this.entite_mouse_downed) {
- if (this.entite_mouse_downed.dragged) {
-
-
- this.wait = true;
- let pos = {
- x:this.entite_mouse_downed.item.position.x - this.pos.x,
- y:this.entite_mouse_downed.item.position.y - this.pos.y
- };
-
-
- let {af, mm, p} = this.computeNewEntitePos(pos);
-
- let pid = this.concernement.entites_byid[this.entite_mouse_downed.item.item_id].id;
- this.recordNewEntitePos(pid, af, mm, p)
- .then((parag) => {
-
-
- this.reloadConcernementEntites(this.concernement.id)
- .then(() => {
- this.wait = false;
- });
- })
- }
- this.entite_mouse_downed = null;
- }
- }.bind(this);
-
- },
- computeNewEntitePos(pos){
-
- let af = pos.y >= 0 ? 0 : 1;
-
-
- let mm = parseFloat(Math.atan(pos.x/Math.abs(pos.y)) * (180/Math.PI)).toFixed(2);
-
-
- let r = Math.sqrt(Math.pow(pos.x,2)+Math.pow(pos.y,2));
-
-
- let ext_circle_factor = 1;
- let r_max = this.ray * ext_circle_factor * this.details_zoom_scale;
- let r_slope = (100 - 0) / (r_max - 0);
- let p = Math.max(0, 100 - parseFloat(0 + r_slope * (r - 0)).toFixed(2));
-
- return {af, mm, p};
- },
- recordNewEntitePos(pid, af, mm, p){
- return new Promise((resolve, reject) => {
-
- const params = {
- id: [{'value': pid}],
- type: 'entite_concernement',
- 'field_actuel_future': [{'value': af}],
- 'field_menace_maintien_degres': [{'value': mm}],
- 'field_prise': [{'value': p}]
- };
-
- const configs = {
- headers: {'X-CSRF-Token': this.csrf_token}
- };
-
- REST.patch(`/entity/paragraph/${pid}?_format=json`, params, configs)
- .then(({ data }) => {
- console.log('concernementMapItem REST patch parag entite', data)
- resolve(data);
- })
- .catch(error => {
- console.warn(`Issue with patch ${this.data.entitytype} ${this.data.bundle}`, error)
- Promise.reject(error)
- })
- });
- },
- resetHoverElmt(){
-
- setTimeout(()=>{
- this.setHoverElmt(null);
- }, 100);
- },
-
- getOpeningAvailableScale(){
-
- let header = document.querySelector('header#header');
- let header_height = header.clientHeight;
- let map_nav = document.querySelector('nav#map-nav');
- let map_nav_height = map_nav.clientHeight;
- let s_h = (this.canvas.height - header_height - map_nav_height) / (this.ray*2*1.15);
- let s_w = (this.canvas.width - this.cartouch_width) / (this.ray*2*1.7);
- return Math.min(s_h, s_w)
- },
- openClose(open) {
-
- console.log(`ConcernementsMapItem openClose ${this.id} openClose: ${open}`);
- if (this.tween) {
- this.tween.stop();
- }
- if (open) {
- this.is_opening = true;
-
- this.setPaperContents();
- this.handlePaperVisibilityOnBeforeOpen();
- let s = this.getOpeningAvailableScale();
-
-
- this.tween = new Tween.Tween({s: this.scale, x: this.pos.x, y: this.pos.y, o: 0})
- .to({
- s: s,
- x: (this.canvas.width - this.cartouch_width) / 2,
- y: this.canvas.height / 2,
- o: 0.8
- }, 800)
- .onUpdate((obj) => {
-
-
-
- this.paper_main_object.scale(1 / this.scale);
-
-
- this.paper_main_object.scale(obj.s);
-
- this.resetSuperpositionsConstraintsScaling(obj.s);
-
- this.prev_scale = this.scale;
- this.scale = this.mapitem.scale = obj.s;
- this.details_zoom_scale = this.scale * this.detailsZoomValue;
- this.opacity = obj.o;
-
- this.pos = {x:obj.x, y:obj.y};
- Matter.Body.setPosition(this.body, this.pos);
- })
- .onComplete((obj) => {
-
-
- this.prev_scale = this.scale = obj.s;
- this.details_zoom_scale = this.scale * this.detailsZoomValue;
- this.mapitem.scale = this.scale;
- this.opacity = obj.o;
- this.pos = {x:obj.x, y:obj.y};
- Matter.Body.setPosition(this.body, this.pos);
-
- this.handlePaperVisibilityOnOpened();
-
- this.constraint = Matter.Constraint.create({
- pointA: this.pos,
- bodyB: this.body,
- stiffness: 1,
- damping: 0,
- length: 0
- });
- Matter.Composite.add(this.matterEngine.world, [this.body, this.constraint]);
-
-
-
- this.paper_main_object.sendToBack();
- this.is_opening = false;
- });
-
- Matter.Events.off(this.matterEngine, "afterUpdate", this.onAfterEngineUpdate);
- Matter.Events.on(this.matterEngine, "afterUpdate", this.onAfterEngineUpdate);
- } else {
- this.setDetailsZoomValue(1);
- this.updateDetailsZoomScale();
-
- this.is_closing = true;
- if(this.constraint){
- Matter.Composite.remove(this.matterEngine.world, this.constraint);
- }
-
-
-
-
- this.handlePaperVisibilityOnBeforeClose();
- this.setOpenedEntiteId(null);
-
-
- this.tween = new Tween.Tween({s: this.scale, o: 1})
- .to({s: 1, o: 0}, 500)
- .onUpdate((obj) => {
-
-
-
-
-
- this.paper_main_object.scale(1 / this.scale);
-
-
- this.paper_main_object.scale(obj.s);
-
-
- if (this.concernement.superposition_constraints_id
- && this.concernement.superposition_constraints_id[this.id]
- && this.concernement.superposition_constraints_id[this.id].length)
- {
-
- let all_constrains = Matter.Composite.allConstraints(this.matterEngine.world);
-
-
- for(let constraint_id of this.concernement.superposition_constraints_id[this.id]) {
-
- let constraint;
- for (const c of all_constrains) {
- if (c.id === constraint_id) {
- constraint = c;
- break;
- }
- }
- if (constraint) {
-
- let ab = this.cid === constraint.concernementA.id ? 'A' : 'B';
- let point = constraint[`point${ab}`];
-
- let oripoint = Matter.Vector.create(point.x / this.scale, point.y / this.scale)
-
- let newpoint = Matter.Vector.create(oripoint.x * obj.s, oripoint.y * obj.s)
- constraint[`point${ab}`] = newpoint;
- }
- }
- }
-
- this.prev_scale = this.scale;
- this.scale = obj.s;
- this.mapitem.scale = this.scale;
- this.details_zoom_scale = this.scale * this.detailsZoomValue;
- this.opacity = obj.o;
- })
- .onComplete((obj) => {
- this.prev_scale = this.scale = 1;
- this.mapitem.scale = this.scale;
- this.details_zoom_scale = this.scale * this.detailsZoomValue;
- this.handlePaperVisibilityOnClosed();
- this.clearPaperContents();
-
- this.setDetailsZoomValue(1);
- this.is_closing = false;
- });
- }
- this.tween.easing(Tween.Easing.Quadratic.InOut).start();
- },
- resetSuperpositionsConstraintsScaling(s){
- if (this.concernement.superposition_constraints_id
- && this.concernement.superposition_constraints_id[this.id]
- && this.concernement.superposition_constraints_id[this.id].length)
- {
-
- let all_constrains = Matter.Composite.allConstraints(this.matterEngine.world);
-
-
- for(let constraint_id of this.concernement.superposition_constraints_id[this.id]) {
-
- let constraint;
- for (const c of all_constrains) {
- if (c.id === constraint_id) {
- constraint = c;
- break;
- }
- }
- if (constraint) {
-
- let ab = this.cid === constraint.concernementA.id ? 'A' : 'B';
- let point = constraint[`point${ab}`];
-
- let oripoint = Matter.Vector.create(point.x / this.scale, point.y / this.scale)
-
- let newpoint = Matter.Vector.create(oripoint.x * s, oripoint.y * s)
- constraint[`point${ab}`] = newpoint;
- }
- }
- }
- },
- async resetMapItemPosition(){
- await nextTick();
- console.log('resetMapItemPosition');
- this.pos = this.paper_main_object.position = {
- x: (this.canvas.width - this.cartouch_width) / 2,
- y: this.canvas.height / 2
- };
- this.constraint.pointA = this.pos;
- console.log('resetMapItemPosition', this.cartouch_width, this.pos);
- Matter.Body.setPosition(this.body, this.pos);
- },
- async resetMapItemScale(){
- await nextTick();
- console.log('resetMapItemScale');
- let s = this.getOpeningAvailableScale();
-
- this.paper_main_object.scale(1 / this.scale);
-
- this.paper_main_object.scale(s);
-
- this.resetSuperpositionsConstraintsScaling(s);
-
- this.prev_scale = this.scale = s;
- this.details_zoom_scale = this.scale * this.detailsZoomValue;
- },
-
- onBeforeEngineUpdate (event) {
-
-
-
-
- Tween.update();
- if (this.opened_concernement) {
-
-
- if (this.opened_concernement.opened_mapitem_id !== this.id) {
-
- let pushaside = true;
-
-
- if (this.map_mode === 'superposition') {
- if (this.opened_concernement.superposed_mapitem_id_by_mapitem_id
- && this.opened_concernement.superposed_mapitem_id_by_mapitem_id[this.opened_concernement.opened_mapitem_id])
- {
- let superposed_ids = this.opened_concernement.superposed_mapitem_id_by_mapitem_id[this.opened_concernement.opened_mapitem_id]
- if (superposed_ids.indexOf(this.id) >= 0) {
- pushaside = false;
- }
- }
- }
- if (pushaside) {
- this.pushAside()
- }
- }
- } else if (!this.is_hover){
- if (this.map_mode === 'proximite'
- || this.map_mode === 'superposition'
- || this.map_mode === 'puissancedagir'
- || this.map_mode === 'action'
- || this.map_mode === 'doleancer'){
- this.applyFocusForces();
- } else {
- this.applyNormalForces();
- }
- } else {
-
- Matter.Body.setVelocity(this.body, {x:0, y:0})
- }
-
-
- Matter.Body.setAngle(this.body, 0);
- Matter.Body.setAngularSpeed(this.body, 0);
- },
- applyFocusForces(){
- if(!this.isFocused()) {
- this.pushAside()
- }else{
- this.bringToCenter()
- }
- },
- isFocused(){
- return this.map_mode === 'terraindevie'
- || (this.map_mode === 'proximite' && this.concernement.has_proximites)
- || (this.map_mode === 'superposition' && this.concernement.has_superpositions)
- || (this.map_mode === 'action' && this.concernement.has_agissantes)
- || (this.map_mode === 'puissancedagir' && this.concernement.has_puissancedagir)
- || (this.map_mode === 'doleancer' && this.concernement.has_doleance);
- },
- pushAside(){
-
-
-
-
-
- let pseudo_center_x = this.opened_concernement
- ? (this.canvas.width - this.cartouch_width) / 2
- : this.canvas.width / 2;
-
- let dir = this.map_mode === 'superposition'
- && this.concernement.superposition_constraints_id
- && this.concernement.superposition_constraints_id[this.id]
- && this.concernement.superposition_constraints_id[this.id].length
- ? 1
- : this.pos.x > pseudo_center_x
- ? 1
- : -1;
-
- if (this.map_mode === 'doleancer') {
- dir = 1;
- }
-
- let minp = 0;
- let maxp = dir < 0
- ? pseudo_center_x
- : this.canvas.width - pseudo_center_x;
-
- let minf = 0;
- let maxf = 6;
-
- let scale = (maxf-minf) / (maxp-minp);
-
- let dist = dir < 0
- ? this.pos.x
- : this.canvas.width - this.pos.x;
-
-
-
- let x_force = Math.exp(minf + scale*(dist-minp)) * dir;
- let ori_pos = {x:pseudo_center_x, y:this.body.position.y};
- Matter.Body.applyForce(
- this.body,
- ori_pos,
- {
- x: x_force,
- y: 0
- }
- );
- this.body.frictionAir = 0.01;
- },
- bringToCenter(){
-
-
-
-
-
- let pseudo_center_x = this.opened_concernement
- ? (this.canvas.width - this.cartouch_width) / 2
- : this.canvas.width / 2;
- let dir = this.pos.x > pseudo_center_x
- ? -1
- : 1;
-
- let dist = dir < 0
- ? this.pos.x - pseudo_center_x
- : pseudo_center_x - this.pos.x;
- if (dist > this.canvas.width/6) {
-
- let minp = 0;
- let maxp = dir < 0
- ? this.canvas.width - pseudo_center_x
- : pseudo_center_x;
-
-
-
- let xminf = 0;
- let xmaxf = 1;
-
- let xscale = (xmaxf-xminf) / (maxp-minp);
- let x_force = Math.exp(xminf + xscale*(dist-minp)) * dir;
- let ori_pos = dir < 0
- ? {x:this.canvas.width, y:this.body.position.y}
- : {x:0, y:this.body.position.y};
- Matter.Body.applyForce(
- this.body,
- ori_pos,
- {
- x: x_force,
- y: 0
- }
- );
-
-
- let fa_minf = 0;
- let fa_maxf = 20;
-
- let fa_scale = (fa_maxf-fa_minf) / (maxp-minp);
- let fa = Math.exp(fa_minf + fa_scale*(dist-minp)*-1);
- this.body.frictionAir = fa;
-
-
- } else {
- let fa = 0.01;
- let velocity = Matter.Body.getVelocity(this.body);
- if (velocity.x) {
- let velocityx = Math.abs(velocity.x);
-
-
- let velocity_range = [50, 1000];
- let fa_range = [0,3];
- fa = fa_range[0] + (velocityx - velocity_range[0]) * (fa_range[1] - fa_range[0]) / (velocity_range[1] - velocity_range[0]);
-
- } else {
- console.warn(`bringToCenter no velocity`, velocity);
- }
- this.body.frictionAir = fa;
- }
- },
- applyShuffleForces() {
-
-
-
-
-
-
- let pseudo_center_x = this.opened_concernement
- ? (this.canvas.width - this.cartouch_width) / 2
- : this.canvas.width / 2;
-
- let dir = this.pos.x > pseudo_center_x
- ? -1
- : 1;
-
- let dist = dir < 0
- ? this.pos.x - pseudo_center_x
- : pseudo_center_x - this.pos.x;
- dist = dist > 1000 ? 1000 : dist;
-
- if (dist > this.canvas.width/6) {
-
- let minp = 0;
- let maxp = dir < 0
- ? this.canvas.width - pseudo_center_x
- : pseudo_center_x;
-
- let xminf = 0;
-
- let xmaxf = 2 + Math.random()*2;
-
- let xscale = (xmaxf-xminf) / (maxp-minp);
-
- let x_velocity = Math.exp(xminf + xscale*(dist-minp))*dir;
-
-
-
- let yminf = 1;
-
- let ymaxf = 4 + Math.random()*2;
-
- let yscale = (ymaxf-yminf) / (maxp-minp);
-
- let y_velocity = Math.exp(yminf + yscale*(dist-minp)) * (Math.random() > 0.5 ? 1 : -1);
-
-
-
-
- Matter.Body.setVelocity(this.body, {x: x_velocity, y: y_velocity});
- } else {
-
-
-
- }
-
- this.body.frictionAir = 0.01;
- },
- applyNormalForces () {
-
-
-
-
-
-
-
-
- let pseudo_center_x = this.opened_concernement
- ? (this.canvas.width - this.cartouch_width) / 2
- : this.canvas.width / 2;
- let xdir = this.pos.x > pseudo_center_x
- ? -1
- : 1;
-
- let xdist = xdir < 0
- ? this.pos.x - pseudo_center_x
- : pseudo_center_x - this.pos.x;
-
- let pseudo_center_y = this.canvas.height / 2;
- let ydir = this.pos.y > pseudo_center_y
- ? -1
- : 1;
-
- let ydist = ydir < 0
- ? this.pos.y - pseudo_center_y
- : pseudo_center_y - this.pos.y;
- let k = 4;
- if (xdist > this.canvas.width/k || ydist > this.canvas.height/k) {
-
- let minf = 0;
- let maxf = 0.1;
-
-
- let xminp = 0;
- let xmaxp = xdir < 0
- ? this.canvas.width - pseudo_center_x
- : pseudo_center_x;
-
-
- let xscale = (maxf-minf) / (xmaxp-xminp);
- let x_force = Math.exp(minf + xscale*(xdist-xminp)) * xdir;
- let xori_pos = xdir < 0
- ? {x:this.canvas.width, y:this.body.position.y}
- : {x:0, y:this.body.position.y};
- Matter.Body.applyForce(
- this.body,
- xori_pos,
- {
- x: x_force,
- y: 0
- }
- );
-
-
- let yminp = 0;
- let ymaxp = ydir < 0
- ? this.canvas.height - pseudo_center_y
- : pseudo_center_y;
-
-
- let yscale = (maxf-minf) / (ymaxp-yminp);
- let y_force = Math.exp(minf + yscale*(ydist-xminp)) * ydir;
- let yori_pos = ydir < 0
- ? {x:this.body.position.x, y:this.canvas.height}
- : {x:this.body.position.x, y:0};
- Matter.Body.applyForce(
- this.body,
- yori_pos,
- {
- x: 0,
- y: y_force
- }
- );
-
-
-
-
-
-
-
-
-
-
- } else {
-
-
-
-
-
-
-
-
-
- this.body.frictionAir = 0.1;
- }
- },
- checkOverflow() {
-
- if (!this.is_open) {
- let pad = 1;
- let circleray = this.body.circleRadius+pad*1.1;
- let respawn = false;
- if(this.pos.x <= pad){ this.pos.x = circleray; respawn=true;}
- if(this.pos.x >= this.canvas.width-pad){ this.pos.x = this.canvas.width - circleray; respawn=true;}
- if(this.pos.y <= pad){ this.pos.y = circleray; respawn=true;}
- if(this.pos.y >= this.canvas.height-pad){ this.pos.y = this.canvas.height - circleray; respawn=true;}
- if (respawn) {
- console.log('respawning');
-
- Matter.Body.setPosition(this.body, {x:this.pos.x, y:this.pos.y});
-
- Matter.Body.setVelocity(this.body, {x:0,y:0});
- }
- }
-
- },
- onAfterEngineUpdate (event) {
- this.checkOverflow();
- this.paper_main_object.position = this.pos = this.body.position;
-
-
- if (this.paper_main_object.opacity < 9) {
- this.paper_main_object.opacity = this.paper_main_object.opacity * 1.1;
- } else{
- this.paper_main_object.opacity = 1;
- }
-
- this.handlePaperVisibilityOnAfterEnginUpdate()
-
-
-
-
-
- },
- debugDrawMatterBodyCircle(){
- if (this.paper_main_object.children['debug_circle']) {
- this.paper_main_object.children['debug_circle'].remove();
- }
- let debugcircle = new paper.Path.Circle({
- center: this.pos,
-
- radius: this.body.circleRadius,
- strokeColor: '#f00',
- strokeWidth: 1,
- name: 'debug_circle'
- })
- this.paper_main_object.addChild(debugcircle)
- }
- },
- render() {
-
- },
- }
- </script>
|