@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 9.69 kB
JavaScript
import e from"../../../../Color.js";import"../../../../geometry.js";import{lengthDimensionMeasureType as t,LengthDimensionMeasureType as n}from"../../../../analysis/dimensionUtils.js";import{cyclicalDegrees as r}from"../../../../core/Cyclical.js";import{rad2deg as o}from"../../../../core/mathUtils.js";import{isNone as i,unwrapOr as a}from"../../../../core/maybe.js";import{pt2px as s}from"../../../../core/screenUtils.js";import{i as c,k as m}from"../../../../chunks/mat4.js";import{c as d}from"../../../../chunks/mat4f64.js";import{g as p,c as u,b as l,f,e as g,k as h,l as y,s as v,w as S}from"../../../../chunks/vec3.js";import{c as j,Z as M,f as x}from"../../../../chunks/vec3f64.js";import{fromPositionAndNormal as w,create as H,signedDistance as P,normal as T}from"../../../../geometry/support/plane.js";import{sv3d as C}from"../../../../geometry/support/vectorStacks.js";import{clonePoint as b}from"../../../../layers/graphics/hydratedFeatures.js";import{isValidComputation as k,computeGeometryFromDimension as O,computationToGeometryDependencies as z,headingFromGeometry as R,computeOffsetForPoint as U,computeSegmentForMeasureType as D,computeOffsetAxis as F,directUp as E,directStartToEnd as L,dimensionStartToEnd as A}from"./lengthDimensionUtils.js";import{settings as G}from"./settings.js";import{Manipulator3D as I}from"../../interactive/Manipulator3D.js";import{createSphereManipulator as W,worldScaledManipulatorSettings as B,createRotateManipulator as N,updateRotateManipulator as V,calculateInputRotationTransform as Z,calculateTranslateRotateFromBases as q}from"../../interactive/manipulatorUtils.js";import{RenderObject as J}from"../../interactive/RenderObject.js";import{screenToMap3D as K,screenToRenderPlane as Q,hideManipulatorWhileDragging as X}from"../../interactive/editingTools/dragEventPipeline3D.js";import{EuclideanSegment as Y}from"../../interactive/visualElements/support/Segment.js";import{MARKER_SIZE_PER_LINE_WIDTH as $}from"../../support/engineContent/marker.js";import{createPolylineGeometry as _}from"../../webgl-engine/lib/GeometryUtil.js";import{createManipulatorDragEventPipeline as ee,resetProperties as te,EventPipeline as ne}from"../../../interactive/dragEventPipeline.js";import{ManipulatorStateCustomFlags as re,ManipulatorStateFlags as oe}from"../../../interactive/interfaces.js";import ie from"../../../../geometry/Point.js";class ae{constructor(e){this.start=e.start,this.end=e.end,this.offset=e.offset,this.heading=e.heading,this.rotation=e.rotation,this.direct=e.direct,this.horizontal=e.horizontal,this.vertical=e.vertical}manipulatorName(e){return Object.keys(this).find((t=>this.hasOwnProperty(t)&&e===this[t]))}values(){return[this.start,this.end,this.offset,this.heading,this.rotation,this.direct,this.horizontal,this.vertical]}forEachMeasureTypeManipulator(e){for(const n of t)e(this.manipulatorForMeasureType(n),n)}manipulatorForMeasureType(e){switch(e){case n.Direct:return this.direct;case n.Horizontal:return this.horizontal;case n.Vertical:return this.vertical}}}function se(t,n){const r=W(t,e.toUnitRGB(G.pointManipulators.color),G.pointManipulators.opacity,Le);return r.available=!1,r.grabCursor="crosshair",r.radius=G.pointManipulators.radius,r.metadata=n.metadata,r.collisionPriority=1,r}function ce(e,t){const n=[x(-.5,0,0),x(.5,0,0)],{lengthFraction:r}=G.offsetManipulator,o=_(t.unfocusedMaterial,n.map((e=>p(j(),e,r)))),i=o.instantiate({material:t.focusedMaterial});return new I({view:e,renderObjects:[new J(o,oe.Unfocused|oe.Selected|Le),new J(i,oe.Focused|Le)],collisionType:{type:"line",paths:[n]},radius:Ee(t.lineSizePt)/2,metadata:t.metadata,available:!1,...B})}function me(e,{lineSizePt:t,material:n}){const{calloutOffsetPx:r,calloutOpacity:o,calloutWidth:i,discScale:a,focusMultiplier:c}=G.orientationManipulator;return{calloutLength:.25*$*G.markers.lineSizeFraction*s(t)+r,calloutOpacity:o,calloutWidth:i,customStateMask:Le,discScale:a,focusMultiplier:c,material:n,metadata:e}}function de(e,t){return N(e,me(t.metadata,t))}function pe(e,t){V(e,me(e.metadata,t))}function ue(e,t){const n=[x(-.5,0,0),x(.5,0,0)],{lengthFraction:r}=G.offsetManipulator,o=_(t.thinOffsetManipulatorMaterial,n),i=_(t.unfocusedMaterial,n.map((e=>p(j(),e,r)))),a=i.instantiate({material:t.focusedMaterial});return new I({view:e,renderObjects:[new J(i,oe.Unfocused|Le),new J(a,oe.Focused|Le),new J(o,Le)],collisionType:{type:"line",paths:[n]},radius:Ee(t.lineSizePt)/2,available:!1,metadata:t.metadata,...B})}function le(e,{isStart:t,createSnappingPipelineStep:n,dimension:r,onUpdate:o,view:i}){const a=t?"startPoint":"endPoint",s=ee(e,((e,t,s,c)=>{const m=X(e),{snappingStep:d,cancelSnapping:p}=n(c);s=s.next(m).next(te(r,[a,"measureType","orientation"])).next(p),t.next(m).next(K(i)).next(...d).next((e=>{const t=b(e.mapEnd,new ie);o("startPoint"===a?{startPoint:t}:{endPoint:t})}))}));return[s]}function fe(e,{computation:t,view:n}){return[ee(e,((e,r,o)=>{if(!k(t)||!e.selected)return;const{geometry:i,dimension:a}=t,s=X(e);r.next(s).next(Me(n,a,i.dimensionSegment,i.primaryOffsetAxis)),o.next(s).next(te(a,["offset"]))}))]}function ge(e,{computation:t,view:n}){return[ee(e,((e,r,o)=>{ve({cancel:o,computation:t,settingHeading:!0,steps:r,view:n})}))]}function he(e,{computation:t,view:n}){return[ee(e,((e,r,o)=>{ve({cancel:o,computation:t,settingHeading:!1,steps:r,view:n})})),e.events.on("immediate-click",(e=>{ye(e,t,n)}))]}function ye(e,t,n){const{dimension:o,geometry:a}=t;if(90===o.orientation||270===o.orientation)return o.orientation=0,void e.stopPropagation();if(i(a))return;const{renderCoordsHelper:s}=n,c=O({...z(t),orientation:90},s),m=O({...z(t),orientation:270},s);if(i(c)||i(m))return;const d=R(c,s),p=R(m,s),u=xe(a,n),l=r.shortestSignedDiff(u,d),f=r.shortestSignedDiff(u,p);o.orientation=Math.abs(l)<Math.abs(f)?90:270,e.stopPropagation()}function ve(e){const{cancel:t,computation:n,settingHeading:r,steps:i,view:s}=e;if(!k(n))return;const{renderCoordsHelper:c}=s,{dimension:m,geometry:d}=n,p=j(),l=Oe(j(),d,d.directSegment,c),f=ze(C.get(),{forHeading:r,geometry:d,renderCoordsHelper:c}),g=w(l,f,H()),h=a(m.orientation,r?()=>R(d,s.renderCoordsHelper):0);i.next(Q(s,g)).next((e=>{"start"===e.action&&u(p,e.renderStart);const t=T(g),n=Z(p,e.renderEnd,l,t);let i=h-o(n);r||(i=Se(i)),m.orientation=i})),t.next(te(m,["orientation"]))}function Se(e){const t=r.normalize(e)%90;return t<G.orientationSnapThresholdDegrees?e-t:90-t<G.orientationSnapThresholdDegrees?e+(90-t):e}function je(e,{computation:t,manipulatorMeasureType:r,view:o}){let i=n.Direct,a=0,s=0;return[e.events.on("grab-changed",(n=>{if("start"!==n.action||!k(t))return;const{dimension:c,geometry:m}=t;i=c.measureType,a=c.offset,s=c.orientation;const d=u(C.get(),e.renderLocation);c.measureType=r,c.offset=U(d,r,m,o.renderCoordsHelper),c.orientation=0})),ee(e,((e,n,c)=>{if(!k(t))return;const{geometry:m,dimension:d}=t,{renderCoordsHelper:p}=o,u=D(We,r,t,p),l=F(C.get(),{measureType:r,directSegment:m.directSegment,renderCoordsHelper:p}),f=X(e);n.next(f).next(Me(o,d,u,l)),c.next(f).next((e=>(d.measureType=i,d.offset=a,d.orientation=s,e)))}))]}function Me(e,t,n,r){const o=l(C.get(),n.endRenderSpace,n.startRenderSpace);f(o,o,r);const i=w(n.startRenderSpace,o,H()),a=w(n.startRenderSpace,r,H()),s=t.offset;let c,m=0;const d=new ne;return d.next(Q(e,i)).next((n=>{"start"===n.action&&(m=P(a,n.renderStart));const r=(P(a,n.renderEnd)-m)*e.renderCoordsHelper.unitInMeters;t.offset=s+r,c=n})),e=>(d.execute(e),c)}function xe(e,t){const{directSegment:n}=e,{renderCoordsHelper:r}=t,o=E(C.get(),e,r),i=L(C.get(),e),a=f(C.get(),i,o),{viewForward:s}=t.state.camera;g(a,s)>0&&p(a,a,-1);const c=n.eval(.5,C.get());return r.headingAtPosition(c,a)}function we(e,t,n){const{dimensionSegment:r,primaryOffsetAxis:o}=t,i=A(Ae,t),a=h(i,M)?c(Ie):q(i,o,M,Ie),s=Math.max(y(i),G.offsetManipulator.minLengthMeters/n.unitInMeters);m(a,a,v(Ae,s,s,s)),e.modelTransform=a,e.renderLocation=r.eval(.5,Ae)}function He(e,t,n){Te(e,t,n,{forHeading:!0})}function Pe(e,t,n){Te(e,t,n,{forHeading:!1})}function Te(e,t,n,{forHeading:r}){const{dimension:o,geometry:i}=t,{primaryOffsetAxis:a}=i,s=p(Ce,a,o.offset>=0?1:-1),c=ze(be,{forHeading:r,geometry:i,renderCoordsHelper:n});f(c,c,s);const m=q(s,c,M,Ie);e.modelTransform=m,e.renderLocation=Oe(Ae,i,i.dimensionSegment,n)}const Ce=j(),be=j();function ke(e,t,n,r){const{geometry:o}=t,i=D(We,n,t,r),a=F(Ae,{measureType:n,directSegment:o.directSegment,renderCoordsHelper:r}),s=S(Ge,i.endRenderSpace,i.startRenderSpace),c=q(s,a,M,Ie),d=y(s);m(c,c,v(Ge,d,d,d)),e.modelTransform=c,e.renderLocation=i.eval(.5,Ge)}function Oe(e,t,n,r){const{startRenderSpace:o,endRenderSpace:i}=n,a=Re(t,r)?o:i;return u(e,a)}function ze(e,{forHeading:t,geometry:n,renderCoordsHelper:r}){return t?E(e,n,r):A(e,n,{invert:!0})}function Re(e,t){const n=L(Ue,e),r=E(De,e,t);return g(n,r)>0}const Ue=j(),De=j();function Fe(e){return s(e)+G.offsetManipulator.linePaddingPx}function Ee(e){return s(e)+G.offsetManipulator.focusedLinePaddingPx}const Le=re.Custom1,Ae=j(),Ge=j(),Ie=d(),We=new Y;export{Le as DidPointerMoveRecentlyFlag,ae as LengthDimensionManipulators,xe as automaticHeadingFromCamera,ue as createMeasureTypeManipulator,ce as createOffsetManipulator,de as createOrientationManipulator,se as createPointManipulator,Ee as focusedOffsetWidth,ge as headingManipulatorHandles,je as measureTypeManipulatorHandles,fe as offsetManipulatorHandles,le as pointManipulatorHandles,he as rotationManipulatorHandles,Se as snapOrientationToNearestRightAngle,Fe as unfocusedOffsetWidth,He as updateHeadingManipulatorTransform,ke as updateMeasureTypeManipulatorTransform,we as updateOffsetManipulatorTransform,pe as updateOrientationManipulator,Pe as updateRotationManipulatorTransform};