/*
 * JaamSim Discrete Event Simulation
 * Copyright (C) 2019 JaamSim Software Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.jaamsim.SubModels;

import java.util.ArrayList;

import com.jaamsim.DisplayModels.DisplayModel;
import com.jaamsim.Graphics.Region;
import com.jaamsim.input.Input;
import com.jaamsim.input.InputAgent;
import com.jaamsim.math.Vec3d;
import com.jaamsim.units.DistanceUnit;

public class SubModelRegion extends Region {

	private CompoundEntity subModel;

	{
		alignmentInput.setDefaultValue(new Vec3d());
		sizeInput.setDefaultValue(new Vec3d(1.0d, 1.0d, 0.0d));
		ArrayList<DisplayModel> def = new ArrayList<>(1);
		def.add((DisplayModel) getJaamSimModel().getNamedEntity("RegionRectangle"));
		displayModelListInput.setDefaultValue(def);

		positionInput.setHidden(true);
		sizeInput.setHidden(true);
		relativeEntity.setHidden(true);
		alignmentInput.setHidden(true);
		orientationInput.setHidden(true);
		scaleInput.setHidden(true);
	}

	public SubModelRegion() {}

	public void setSubModel(CompoundEntity sm) {
		subModel = sm;
		InputAgent.applyArgs(this, "RelativeEntity", subModel.getName());
	}

	@Override
	public void updateForInput( Input<?> in ) {
		super.updateForInput( in );

		if (in == positionInput) {
			InputAgent.applyVec3d(subModel, "RegionPosition", positionInput.getValue(), DistanceUnit.class);
			return;
		}

		if (in == sizeInput) {
			InputAgent.applyVec3d(subModel, "RegionSize", getInternalSize(), DistanceUnit.class);
			return;
		}
	}

	@Override
	public boolean isGraphicsNominal() {
		return true;
	}

}

@@ -1762,32 +1762,99 @@
 ositionInput) %7B%0A
+%09%09%09Vec3d pos = positionInput.getValue();%0A%09%09%09if (subModel != null)%0A%09
 %09%09%09InputAgent.ap
@@ -1893,37 +1893,16 @@
 on%22, pos
-itionInput.getValue()
 , Distan
@@ -1957,16 +1957,77 @@
 nput) %7B%0A
+%09%09%09Vec3d size = getInternalSize();%0A%09%09%09if (subModel != null)%0A%09
 %09%09%09Input
@@ -2067,33 +2067,20 @@
 nSize%22, 
-getInternalS
+s
 ize
-()
 , Distan

fix null pointer error in unit test for SubModelRegion keywords